RabbitMQ python worker script using 100% CPU

I worte this python script that acts as an RPC server by modifying the default RPC example in the RabbitMQ tutorial found here . It works great on my laptop. But when I run it in amazon ec2 High CPU Medium Instance with these specifications:

1.7 GB of memory

5 EC2 computing units (2 virtual cores with 2.5 EC2 computing units)

350 GB instance storage

It occupies a 100% processor. Although my laptop with almost the same configuration works with less than 4% of CPU usage. I run this on Ubuntu-12.04 on 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?

+6
source share
1 answer

Finally found a problem. It was a bug in Pika, I got this information from the rabbitmq mailing list. I installed pika via pypi. pip install pika .

To fix this remote pika

pip uninstall pika

and reinstall it from git

pip install git+https://github.com/pika/pika.git .

And that decided.

+5
source

All Articles