Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@i110
Copy link
Contributor

@i110 i110 commented Dec 11, 2019

Similar to #2080, expose bytes_read information of httpclient, and let the logger access to them using proxy-response-bytes(-header|-body).

Copy link
Member

@kazuho kazuho left a 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;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@kazuho kazuho left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants