You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Send changes without waiting for a CONTINUE request #3459
I think once we have #3296 we should just increase the batch timeout for changefeeds to something much higher (or make them not time out at all).
Or do you mean we should never wait for the client sending a CONTINUE, even after we've just sent it a (batch of) change(s)? Would we stream all changes over the connection as soon as the changes happen then?
I think that might be problematic because if the client doesn't process the changes quickly enough, they would fill up the TCP buffer blocking other concurrent queries running over the same connection.
@danielmewes, to be honest, that's exactly how you're supposed to leverage TCP buffers to implement rate-limiting. The client should keep reading out results regardless, but if the server is stuck on the TCP write buffer being full, it should put pressure back on the queries which are trying to send results.
@Tryneus Yes, that only works well if you have a single data stream on the connection though. If we want to leverage #3296 to run multiple queries in parallel over a single TCP connection, we would probably not want one of them to be able to back off all the other ones.
@Tryneus Ah fair enough, that might actually work. The second question then is what to do with all the incoming changes on the client. You probably don't want to load them all into memory indefinitely if they are not getting processed from the cursor.
On the server we currently handle this by discarding changes if the client isn't reading them quickly enough, and instead send it a "N changes skipped" notification. If we always push them out to the client regardless of whether the client is processing them or not, we would have to implement a similar logic in the client then right?
@danielmewes, I had considered that, but it still leaves us with the same problem in the case of cursors. Unless we fill up a buffer on the client side and use peek to refuse to read out more if the buffer is full - which would lead to a deadlock if the client is waiting on a different result.
I actually think just sticking with the current cursor protocol for changefeeds (i.e. send a CONTINUE if you want more data) would be perfectly fine. Sure, there's an additional roundtrip involved after each batch the client is receiving, but that feels acceptable to me.
That's basically the goal of the current system: we wanted the client to be responsible for notifying the server when it wants more data, because it's easier to handle the case where we get backed up on the server than to expect users to handle it in the client. If we wanted to get rid of the current batching system, I think we should add some explicit flow control (i.e. the "give me a new batch" messages would be replaced with "send me more data" and "stop sending me more data" messages) rather than relying on TCP's flow control, just because it's easier to reason about and tweak.
The clients all prefetch one batch ahead, so right now if the network latency is small we should get a flow rate roughly equal to the production rate on the server or the consumption rate on the client, whichever is slower.
Activity
danielmewes commentedon Dec 18, 2014
I think once we have #3296 we should just increase the batch timeout for changefeeds to something much higher (or make them not time out at all).
Or do you mean we should never wait for the client sending a CONTINUE, even after we've just sent it a (batch of) change(s)? Would we stream all changes over the connection as soon as the changes happen then?
I think that might be problematic because if the client doesn't process the changes quickly enough, they would fill up the TCP buffer blocking other concurrent queries running over the same connection.
AtnNn commentedon Dec 18, 2014
That is what I have in mind, but you raise a valid objection I had not thought about.
Tryneus commentedon Dec 18, 2014
@danielmewes, to be honest, that's exactly how you're supposed to leverage TCP buffers to implement rate-limiting. The client should keep reading out results regardless, but if the server is stuck on the TCP write buffer being full, it should put pressure back on the queries which are trying to send results.
danielmewes commentedon Dec 18, 2014
@Tryneus Yes, that only works well if you have a single data stream on the connection though. If we want to leverage #3296 to run multiple queries in parallel over a single TCP connection, we would probably not want one of them to be able to back off all the other ones.
Tryneus commentedon Dec 18, 2014
I'm sure we can implement a way for queries to fairly share the outbound buffer. Round-robin would probably be sufficient.
danielmewes commentedon Dec 18, 2014
@Tryneus Ah fair enough, that might actually work. The second question then is what to do with all the incoming changes on the client. You probably don't want to load them all into memory indefinitely if they are not getting processed from the cursor.
On the server we currently handle this by discarding changes if the client isn't reading them quickly enough, and instead send it a "N changes skipped" notification. If we always push them out to the client regardless of whether the client is processing them or not, we would have to implement a similar logic in the client then right?
Tryneus commentedon Dec 18, 2014
@danielmewes, I had considered that, but it still leaves us with the same problem in the case of cursors. Unless we fill up a buffer on the client side and use peek to refuse to read out more if the buffer is full - which would lead to a deadlock if the client is waiting on a different result.
Maybe we should just change to SCTP.
danielmewes commentedon Dec 18, 2014
I actually think just sticking with the current cursor protocol for changefeeds (i.e. send a CONTINUE if you want more data) would be perfectly fine. Sure, there's an additional roundtrip involved after each batch the client is receiving, but that feels acceptable to me.
mlucy commentedon Dec 18, 2014
That's basically the goal of the current system: we wanted the client to be responsible for notifying the server when it wants more data, because it's easier to handle the case where we get backed up on the server than to expect users to handle it in the client. If we wanted to get rid of the current batching system, I think we should add some explicit flow control (i.e. the "give me a new batch" messages would be replaced with "send me more data" and "stop sending me more data" messages) rather than relying on TCP's flow control, just because it's easier to reason about and tweak.
The clients all prefetch one batch ahead, so right now if the network latency is small we should get a flow rate roughly equal to the production rate on the server or the consumption rate on the client, whichever is slower.