Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pika performace #1197

Open
Gsantomaggio opened this issue Mar 25, 2019 · 6 comments
Open

Pika performace #1197

Gsantomaggio opened this issue Mar 25, 2019 · 6 comments
Assignees
Milestone

Comments

@Gsantomaggio
Copy link
Contributor

I am opening this issue after a conversation with @lukebakken
here the thread

RabbitMQ test with different libraries

I made a few tests with different client libraries.

Environment:

  • Laptop 12 cores, 32 gb ram
  • Two rabbitmq nodes in cluster ( same machine)
  • RabbitMQ version 3.7.13 - Erlang 21.2.4
  • 64 async threads for each server
  • Ubuntu 18.04
  • Two Python processes running
(.venv3) ➜  py-amqp git:(master) ✗ pip freeze
amqp==2.4.2
atomicwrites==1.3.0
attrs==19.1.0
librabbitmq==2.0.0
more-itertools==6.0.0
pika==0.13.1
pluggy==0.9.0
py==1.8.0
PyAMQP==0.0.7.1
pytest==4.3.1
six==1.12.0
vine==1.3.0
(.venv3) ➜  py-amqp git:(master) ✗

Here is the code:

import time
import uuid
import sys
class PyAmqpTest:

    def publish(self, rm):
        c = amqp.Connection(host=rm)
        channel = c.channel()
        qname = str(uuid.uuid4())
        message = amqp.Message(
            channel=channel,
            body='the quick brown fox jumps over the lazy dog',
            properties=dict(content_type='application/json',
                            content_encoding='utf-8'))

        channel.queue_declare(queue=qname, auto_delete=False)
        print("start: %s" % (time.ctime(time.time())))
        for i in range(1, 900000):
            channel.basic_publish(message, routing_key=qname)
        print("end: %s" % (time.ctime(time.time())))

    def thread_publish(self, rm):
        for i in range(1, 15):
            _thread.start_new_thread(self.publish, (rm,))


print('starting .. %s' % sys.argv[1])
x = PyAmqpTest()
x.thread_publish(sys.argv[1])

input("Press Enter to continue...")

py-amqp

import amqp as amqp

and then

python3 py_amqp_publish.py localhost:5674 
python3 py_amqp_publish.py localhost:5672

around 18.000 messages per second

librabbitmq

import librabbitmq as amqp

and then

python3 py_amqp_publish.py localhost:5674 
python3 py_amqp_publish.py localhost:5672

around 102.000 messages per second

Pika

import _thread

import pika
import time
import uuid
import sys


class PyPikaTest:

    def publish(self, rm):
        c = pika.BlockingConnection(pika.ConnectionParameters(port=rm))

        channel = c.channel()
        qname = str(uuid.uuid4())
        channel.queue_declare(queue=qname, auto_delete=False)
        _properties = pika.BasicProperties(
            content_type='application/json',
            content_encoding='utf-8'
        )
        print("start: %s" % (time.ctime(time.time())))
        for i in range(1, 900000):
            channel.basic_publish(
                exchange='',
                routing_key=qname,
                properties=_properties,
                body='the quick brown fox jumps over the lazy dog'
            )
        print("end: %s" % (time.ctime(time.time())))

    def thread_publish(self, rm):
        for i in range(1, 15):
            _thread.start_new_thread(self.publish, (rm,))


print('starting .. %s' % sys.argv[1])
x = PyPikaTest()
x.thread_publish(sys.argv[1])

input("Press Enter to continue...")

So:

python3 py_pika_publish.py 5672
python3 py_pika_publish.py 5674

about 11.000 messages per second


Thank you

@ponach
Copy link

ponach commented Mar 27, 2019

Just to shed more light into this yet to be explained the huge difference in throughput, I found that using librabbitmq, there's unexplainable message loss meaning not all the messages are received by the messaging queue ( I experimented with 1000000, at the end of the experiment the messaging queue only got 999,820 )

@Gsantomaggio
Copy link
Contributor Author

@ponach Thank you for the feedback.

I don't use librabbitmq in production, but during my tests, I never lost messages.
Here an example:
Screenshot from 2019-03-27 11-15-23

A common error during the tests, is to close the client/connections after the last publish.
The publish is asycronous so you should wait a bit before close it.

Btw I really suggest to open an issue with your problem to the librabbitmq repository, and please attach also code you are using for your tests.

@auvipy
Copy link

auvipy commented Aug 22, 2019

librabbitmq is not recommended for production. we have a plan for improving py-amqp further as it is more feature-rich and less buggy.

@Gsantomaggio
Copy link
Contributor Author

librabbitmq is not recommended for production.

Yes but I am more interested to understand the performance different

@michaelklishin
Copy link
Contributor

The only fair comparison here is with py-amqp. A couple of profiler sessions will yield relevant data. I don't know what other recommendation there can be.

@Gsantomaggio
Copy link
Contributor Author

We can close the issue if you want @michaelklishin @lukebakken
It is not important anymore ( at least for me :) )

@lukebakken lukebakken self-assigned this May 24, 2022
@lukebakken lukebakken added this to the 2.0.0 milestone May 24, 2022
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

No branches or pull requests

5 participants