[rabbitmq-discuss] Python worker consuming 100% cpu

Gavin M. Roy gmr at meetme.com
Thu Feb 14 13:50:00 GMT 2013


It's an issue that is fixed in pika's master branch and will be pushed to
pypi soon. You can test by installing pika with pip from git.

On Thursday, February 14, 2013, Manuchandraprasad R wrote:

> I worte this python script which acts as an RPC server by modifying the
> default RPC example in RabbitMQ tutorial found here<http://www.rabbitmq.com/tutorials/tutorial-six-python.html>.
> It runs fine in my laptop. But when i run it in an amazon ec2 High CPU
> Medium Instance with these specs :
>
> 1.7 GiB of memory
>
> 5 EC2 Compute Units (2 virtual cores with 2.5 EC2 Compute Units each)
>
> 350 GB of instance storage
>
> It takes up 100% CPU. Although my laptop with almost the same config runs
> this with less than 4% CPU use.I run this in Ubuntu-12.04 in both my laptop
> and amazon.
>
> Here is my code
>
>     #!/usr/bin/env python
>     import pika
>     import commands
>     import socket
>     import base64
>
>     connection = pika.BlockingConnection(pika.ConnectionParameters(
>              host='localhost'))
>     channel = connection.channel()
>     channel.queue_declare(queue='rpc_queue')
>     def on_request(ch, method, props, body):
>         #print body
>         body = base64.b64decode(body)
>         print body
>         run = commands.getoutput(body)
>         response = socket.gethostname()
>         print response
>         ch.basic_publish(exchange='',
>                         routing_key=props.reply_to,
>                         properties=pika.BasicProperties(correlation_id = \
>                                                       props.correlation_id),
>                         body=str(response))
>         ch.basic_ack(delivery_tag = method.delivery_tag)
>     channel.basic_qos(prefetch_count=1)
>     channel.basic_consume(on_request, queue='rpc_queue')
>     print " [x] Awaiting RPC requests"
>     channel.start_consuming()
>
>  How can i fix this ?
>
> Manu



-- 

Gavin M. Roy
Chief Technology Officer

<http://www.meetme.com/>
100 Union Square Drive
New Hope, PA 18938
p. +1.215.862.1162 x263
f. +1.215.862.0465

<https://www.facebook.com/pages/MeetMe/21931227129>
<https://twitter.com/meetme>
    <http://www.youtube.com/user/MeetMeVideos>

The public market leader in social discovery. (NYSE MKT: MEET)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130214/5170b101/attachment.htm>


More information about the rabbitmq-discuss mailing list