Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: JsonHttpContent.writeTo() is called twice for each HttpRequest #283

Closed
siom79 opened this issue May 1, 2015 · 5 comments
Closed
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@siom79
Copy link

siom79 commented May 1, 2015

Debugging shows that the method JsonHttpContent.writeTo() is called twice when a HttpRequest is rendered. For the first time it is called to compute the length of the body and for the second time to actually render the JSON string.

First invocation:

"main@1" prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
      at com.google.api.client.http.json.JsonHttpContent.writeTo(JsonHttpContent.java:73)
      at com.google.api.client.util.IOUtils.computeLength(IOUtils.java:113)
      at com.google.api.client.http.AbstractHttpContent.computeLength(AbstractHttpContent.java:139)
      at com.google.api.client.http.AbstractHttpContent.computeLength(AbstractHttpContent.java:117)
      at com.google.api.client.http.AbstractHttpContent.getLength(AbstractHttpContent.java:65)
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:914)

Second invocation:

"main@1" prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
      at com.google.api.client.http.json.JsonHttpContent.writeTo(JsonHttpContent.java:73)
      at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:79)
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)
@ejona86 ejona86 added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Feb 22, 2017
@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Jun 8, 2018
@JustinBeckwith JustinBeckwith removed the 🚨 This issue needs some love. label Jun 25, 2018
@andrey-qlogic
Copy link
Contributor

andrey-qlogic commented Feb 18, 2019

@siom79 , @ajaaym This is not either a bug and a feature. I don't think that a code change is required for this request. That code of the method public long getLength() throws IOException

works as expected. It calls the second method only once when contentLength is -1.

@andrey-qlogic
Copy link
Contributor

@siom79, @ajaaym , @sduskis Please ignore my comment above.
It calls twice here

and here
LowLevelHttpResponse lowLevelHttpResponse = lowLevelHttpRequest.execute();
because we need to calculate a Content-Length. Assume we could drop Content-Length when the length is known but it may not work then for example for retry requests.

@andrey-qlogic
Copy link
Contributor

@ejona86, @JustinBeckwith is the feature request still actual? by the log above I'm not clear about.

@sduskis
Copy link
Contributor

sduskis commented Mar 5, 2019

@andrey-qlogic, yo usaw that the code gets called twice. We should fix that.

@elharo
Copy link
Contributor

elharo commented Mar 15, 2020

I think #910 fixed this. Reopen if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

6 participants