hadoop-hdfs-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yiqun Lin (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HDFS-10658) Reduce JsonFactory instance allocation in StartupProgressServlet
Date Wed, 20 Jul 2016 12:19:20 GMT

     [ https://issues.apache.org/jira/browse/HDFS-10658?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Yiqun Lin updated HDFS-10658:
-----------------------------
    Description: 
Now in class {{StartupProgressServlet}}, it will always create a new {{JsonFactory}} instance
to create a JsonGenerator. The codes:
{code}
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    resp.setContentType("application/json; charset=UTF-8");
    StartupProgress prog = NameNodeHttpServer.getStartupProgressFromContext(
      getServletContext());
    StartupProgressView view = prog.createView();
    JsonGenerator json = new JsonFactory().createJsonGenerator(resp.getWriter());
    try {
      json.writeStartObject();
      json.writeNumberField(ELAPSED_TIME, view.getElapsedTime());
      json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete());
      json.writeArrayFieldStart(PHASES);
      ...
{code}
We can reuse the instance and reduce {{JsonFactory}} instance allocation.

{{JsonFactory}} is also a heavy-weight object like {{ObjectMapper}}. Can see this related
doc, https://github.com/FasterXML/jackson-docs/wiki/Presentation:-Jackson-Performance.

  was:
Now in class {{StartupProgressServlet}}, it will always create a new {{JsonFactory}} instance
to create a JsonGenerator. The codes:
{code}
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    resp.setContentType("application/json; charset=UTF-8");
    StartupProgress prog = NameNodeHttpServer.getStartupProgressFromContext(
      getServletContext());
    StartupProgressView view = prog.createView();
    JsonGenerator json = new JsonFactory().createJsonGenerator(resp.getWriter());
    try {
      json.writeStartObject();
      json.writeNumberField(ELAPSED_TIME, view.getElapsedTime());
      json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete());
      json.writeArrayFieldStart(PHASES);
      ...
{code}
We can reuse the instance and reduce {{JsonFactory}} instance allocation.


> Reduce JsonFactory instance allocation in StartupProgressServlet
> ----------------------------------------------------------------
>
>                 Key: HDFS-10658
>                 URL: https://issues.apache.org/jira/browse/HDFS-10658
>             Project: Hadoop HDFS
>          Issue Type: Bug
>            Reporter: Yiqun Lin
>            Assignee: Yiqun Lin
>         Attachments: HDFS-10658.001.patch
>
>
> Now in class {{StartupProgressServlet}}, it will always create a new {{JsonFactory}}
instance to create a JsonGenerator. The codes:
> {code}
>   protected void doGet(HttpServletRequest req, HttpServletResponse resp)
>       throws IOException {
>     resp.setContentType("application/json; charset=UTF-8");
>     StartupProgress prog = NameNodeHttpServer.getStartupProgressFromContext(
>       getServletContext());
>     StartupProgressView view = prog.createView();
>     JsonGenerator json = new JsonFactory().createJsonGenerator(resp.getWriter());
>     try {
>       json.writeStartObject();
>       json.writeNumberField(ELAPSED_TIME, view.getElapsedTime());
>       json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete());
>       json.writeArrayFieldStart(PHASES);
>       ...
> {code}
> We can reuse the instance and reduce {{JsonFactory}} instance allocation.
> {{JsonFactory}} is also a heavy-weight object like {{ObjectMapper}}. Can see this related
doc, https://github.com/FasterXML/jackson-docs/wiki/Presentation:-Jackson-Performance.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-help@hadoop.apache.org


Mime
View raw message