From f74b88fa0e55b1dd42ddddbec7ecc72ccbbf8cff Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 13 Dec 2012 18:05:26 +0100
Subject: [PATCH] Log only partial response in Luxi when in debug mode

Currently, we log the entire response (at debug level) in the Luxi
replies. This is not a good idea; the logging library operates on
strings, and as such it will use huge amounts of memory: without debug
logging, a certain gnt-job list invocation uses 295MB (+RTS -s) and
2m35s time, when in debug mode, it's 1525MB and 48m!

So we make two changes:

- first, we switch from "show (pp_value a)" to "encode a", which
  generates a non-formatted string rather than a indented one
- second we log only the first 2000 characters; this should be enough
  to understand the first part of the response

We could go for higher, or for logging in batches (that would be
faster, as well).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
---
 htools/Ganeti/Query/Server.hs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/htools/Ganeti/Query/Server.hs b/htools/Ganeti/Query/Server.hs
index 1d2f8e6a8..ab9a43c92 100644
--- a/htools/Ganeti/Query/Server.hs
+++ b/htools/Ganeti/Query/Server.hs
@@ -39,7 +39,6 @@ import Data.Maybe
 import qualified Network.Socket as S
 import qualified Text.JSON as J
 import Text.JSON (showJSON, JSValue(..))
-import Text.JSON.Pretty (pp_value)
 import System.Info (arch)
 
 import qualified Ganeti.Constants as C
@@ -179,7 +178,8 @@ handleClientMsg client creader args = do
         logWarning $ "Failed to execute request: " ++ show err
         return (False, showJSON err)
       Ok result -> do
-        logDebug $ "Result " ++ show (pp_value result)
+        -- only log the first 2,000 chars of the result
+        logDebug $ "Result (truncated): " ++ take 2000 (J.encode result)
         return (True, result)
   sendMsg client $ buildResponse status rval
   return True
-- 
GitLab