[rabbitmq-discuss] Python worker consuming 100% cpu
Manuchandraprasad R
manuchandraprasadr at gmail.com
Thu Feb 14 09:25:13 GMT 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130214/de50e8b9/attachment.htm>
More information about the rabbitmq-discuss
mailing list