You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jo...@apache.org on 2020/06/13 00:05:47 UTC

[impala] 02/03: IMPALA-9847: reduce web UI serialized JSON size

This is an automated email from the ASF dual-hosted git repository.

joemcdonnell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 6ca6e403580dc592c026b4f684d31f8a4dcfae11
Author: Tim Armstrong <ta...@cloudera.com>
AuthorDate: Wed Jun 10 16:52:08 2020 -0700

    IMPALA-9847: reduce web UI serialized JSON size
    
    Switch to using the plain writer in some places, and
    tweak PrettyWriter to produce denser output for the
    debug UI JSON (so that it's still human readable but
    denser).
    
    Testing:
    Manually tested. The profile for the below query went
    from 338kB to 134kB.
    
      select min(l_orderkey) from tpch_parquet.lineitem;
    
    Change-Id: I66af9d00f0f0fc70e324033b6464b75a6adadd6f
    Reviewed-on: http://gerrit.cloudera.org:8080/16068
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/service/impala-hs2-server.cc   | 3 ++-
 be/src/service/impala-http-handler.cc | 6 ++++--
 be/src/util/webserver.cc              | 4 ++++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/be/src/service/impala-hs2-server.cc b/be/src/service/impala-hs2-server.cc
index 3cca3e5..757c4e9 100644
--- a/be/src/service/impala-hs2-server.cc
+++ b/be/src/service/impala-hs2-server.cc
@@ -1042,8 +1042,9 @@ void ImpalaServer::GetRuntimeProfile(
   if (request.format == TRuntimeProfileFormat::THRIFT) {
     return_val.__set_thrift_profile(thrift_profile);
   } else if (request.format == TRuntimeProfileFormat::JSON) {
+    // Serialize to JSON without extra whitespace/formatting.
     rapidjson::StringBuffer sb;
-    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
+    rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
     json_profile.Accept(writer);
     ss << sb.GetString();
     return_val.__set_profile(ss.str());
diff --git a/be/src/service/impala-http-handler.cc b/be/src/service/impala-http-handler.cc
index b2ece97..197100d 100644
--- a/be/src/service/impala-http-handler.cc
+++ b/be/src/service/impala-http-handler.cc
@@ -1111,9 +1111,11 @@ void ImpalaHttpHandler::AdmissionStateHandler(
   string staleness_detail = ac->GetStalenessDetail("", &ms_since_last_statestore_update);
 
   // In order to embed a plain json inside the webpage generated by mustache, we need
-  // to stringify it and write it out as a json element.
+  // to stringify it and write it out as a json element. We do not need to pretty-print
+  // it, so use the basic writer.
   rapidjson::StringBuffer strbuf;
-  PrettyWriter<rapidjson::StringBuffer> writer(strbuf);
+  Writer<rapidjson::StringBuffer> writer(strbuf);
+
   resource_pools.Accept(writer);
   Value raw_json(strbuf.GetString(), document->GetAllocator());
   document->AddMember("resource_pools_plain_json", raw_json, document->GetAllocator());
diff --git a/be/src/util/webserver.cc b/be/src/util/webserver.cc
index cbf2874..fa6a317 100644
--- a/be/src/util/webserver.cc
+++ b/be/src/util/webserver.cc
@@ -805,7 +805,11 @@ void Webserver::RenderUrlWithTemplate(const struct sq_connection* connection,
     // Callbacks may optionally be rendered as a text-only, pretty-printed Json document
     // (mostly for debugging or integration with third-party tools).
     StringBuffer strbuf;
+    // Write the JSON out with human-readable formatting. The settings are tweaked to
+    // reduce extraneous whitespace characters, compared to the default formatting.
     PrettyWriter<StringBuffer> writer(strbuf);
+    writer.SetIndent('\t', 1);
+    writer.SetFormatOptions(kFormatSingleLineArray);
     document.Accept(writer);
     (*output) << strbuf.GetString();
     *content_type = JSON;