Are twisted RPCs guaranteed to arrive in order?
I'm using twisted to implement a client and a server. I've set up RPC between the client and the server. So on the client I do protocol.REQUEST_UPDATE_STATS(stats)
, which translates into sending a message with transport.write
on the client transport that i开发者_如何学编程s some encoded version of ["update_stats", stats]
. When the server receives this message, the dataReceived
function on the server protocol is called, it decodes it, and calls a function based on the message, like CMD_UPDATE_STATS(stats)
in this case.
If, on the client, I do something like:
protocol.REQUEST_UPDATE_STATS("stats1")
protocol.REQUEST_UPDATE_STATS("stats2")
...am I guaranteed that the "stats1"
message arrives before the "stats2"
message on the server?
UPDATE: Edited for more clarity. But now the answer seems obvious - no way.
They will arrive in the order that the request is received by the Python process. This includes the connection setup time plus the packets containing the request data. So no, this is not guaranteed to be the order that the sending processes sent the request, because of network latency, dropped packets, sender-side packet queuing, etc. "In-order" is also loosely defined for distributed systems.
But yes, in general you can count on them being delivered in-order as long as they're separated by a relatively large amount of time (100's of ms over the internet).
精彩评论