Pass # of times called to TCPConnectionNotify.received #1777
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On non-Windows platforms, TCPConnection will read data off of a socket
until:
TCPConnectionNotify.received
returns falseThe last option was introduced via [RFC
to give the programmer more control of when to yield the scheduler. This
was a noble goal but is weakly implemented. In order to exercise better
control, the programmer needs an additional bit of information: the
number of times during this scheduler run that
received
has beencalled.
As we began to use RFC #19 at Sendence it became clear that is wasn't
doing what we wanted. What we hoped to be able to do was read up to X
number of messages off the socket, inject them into our application and
then give up the scheduler.
Our initial implementation was to keep a counter of messages received in
our
TCPConnectionNotify
instances and when it hit a number such as 25or 50, return false to give up the scheduler. This, however, didn't
accomplish what we wanted. The following scenario was possible:
Scheduler run results in 24 calls to
received
. When the next schedulerrun would occur, we'd get 1 more
received
call and return false. Whatwe really wanted was to read no more than 25 messages per scheduler
run.
In order to accomplish this, we added an additional parameter to
TCPConnectionNotify.received
: the number of times during thisscheduler run that
received
has been called (inclusive of the existingcall). This gives much more fine-grained control over when to
"prematurely" give up the scheduler and play nice with other sockets in
the system.
You might think, "why not lower the max read size"? And this certainly
is something you could do, but lowering the max read size, lowers how
large of a chunk we read from the socket during a given system call. In
the case of a high-throughput system, that will greatly increase the
number of system calls thereby lowering performance.
Resolves #1773