Closed ghost closed 5 years ago
Please have some decency and post your findings into this issue instead of just dumping a link.
Your code opens N channels before publishing concurrently and this client has a per-connection lock around channel.open operations. So all threads in your code contend on that lock and possibly more (I couldn't quickly find where published message framing happens: clients often use a per-connection lock for serialised outgoing frames as well).
Pre-allocating channels will avoid contention on the channel management lock.
While I do not understand how multithreading affects. If you do not use threads then the behavior is no different.
import rabbitpy as rbp
def main():
with rbp.Connection(url='amqp://guest:guest@localhost:5672/%2F') as cn:
with cn.channel() as ch:
rbp.Queue(ch, 'queue').declare()
rbp.Message(ch, 'Message').publish('', 'test_queue') # 40ms delay
cn.channel().close() # Any works with channel on that connection and next Publish will with delay
rbp.Message(ch, 'Message').publish('', 'test_queue') # 40ms delay too
if __name__ == '__main__':
main()
Pre-allocation channels will avoid but only in one case, when all channels are pre-allocated if one more opens publications on all (pre-allocated) others will be late.
IMHO this is not an issue in rabbitpy
nor RabbitMQ itself and #116 should be closed. See this comment.
Closing per rabbitmq-server #1763
I observe a strange behavior of the RabbitMQ server. After opening a channel and publishing a message (Basic.Publish), the server sends a acknowledgement packet 40ms after the first received packet of Basic.Publish.
Wireshark dump (image):
Whireshark dump (csv source): dump.txt
The problem is aggravated by the fact that if a channel is opened/closed on a connection, the next publication (Basic.Publish) of the message (through all open channels) will have a 40ms delay.
Our system uses a large number of channels per connection and this behavior negates performance.
Questions:
Below is the minimum working code example and information of the system.
System Information:
rabbitmqctl status:
Thanks!
P.S In the example I use the rabbitpy library. But the behavior is observed in another library - the pika. But judging by the network traffic is not a problem of libraries.