-
Notifications
You must be signed in to change notification settings - Fork 868
expose bytes_read information #2197
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
Conversation
kazuho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR. The design looks like a natural extension and fine, although I think there is an issue in code.
Also, if we are to merge this PR without adding corresponding code to the H2 side, I think we should open a separate issue that tracks it for H2.
| } | ||
|
|
||
| client->super.bytes_read.body += sock->bytes_read; | ||
| client->super.bytes_read.total += sock->bytes_read; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this code is correct.
sock->bytes_read is the total bytes that has been read from the socket. Therefore, you should not be adding that.
Instead, you should be adding delta between the each invocation of the on_xxx callbacks. Or, you can retain the value of sock->bytes_read before starting to receive the headers (or the body), and update bytes_read.xxx in each invocation by calculating the delta from the value at the start.
Also, assuming that this observation is correct, I think you might want to add a test case that slowly sends a response, so that on_body_xxx would be invoked multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sock->bytes_read is the total bytes that has been read from the socket
Is this true? Seeing https://github.com/h2o/h2o/blob/master/lib/common/socket/evloop.c.h#L247, we calculate bytes_read by taking the difference of buffer size every time we do read(2) and read callback is called. Doesn't it mean, it's not total bytes, and we can get the real total bytes by adding up bytes_read?
I added a streaming test case in 98bad3c, and it passes without adding any changes to the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing that out. I think you are correct.
Though that raises another concern: h2o_socket_t::bytes_written and h2o_socket_t::bytes_read have different semantics, even though the names are symmetrical. The former is per-call value (as you correctly point out), whereas the latter is cumulative value.
We should align the semantics. And my preference would be to have cumulative counters for both read and write, as that would be more helpful than per-call values that can be maintained by each module while that module owns the TCP connection. Compared to that, it is much harder to maintain the amount of application data being sent / received using a socket, as the TCP socket might be passed across multiple modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kazuho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you the changes. Looks good. Please merge when CI succeeds.
Similar to #2080, expose
bytes_readinformation of httpclient, and let the logger access to them usingproxy-response-bytes(-header|-body).