RabbitMQ python worker脚本使用100%CPU

Man*_*anu 6 python ubuntu amazon-ec2 rabbitmq

我通过修改这里找到的RabbitMQ教程中的默认RPC示例来编写这个充当RPC服务器的python脚本.它在我的笔记本电脑上运行正常 但是当我在亚马逊ec2高CPU中等实例中使用这些规范运行它时:

1.7 GiB的内存

5个EC2计算单元(2个虚拟核,每个具有2.5个EC2计算单元)

350 GB的实例存储

它占用了100%的CPU.虽然我的笔记本电脑具有几乎相同的配置运行,CPU使用率不到4%.我在笔记本电脑和亚马逊的Ubuntu-12.04中运行它.

这是我的代码

    #!/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()
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题 ?

Man*_*anu 5

终于找到了问题.这是Pika的一个错误,我从rabbitmq的邮件列表中获取了这些信息.我通过pypi安装了pika.pip install pika.

解决这个我卸载的鼠兔

pip uninstall pika

并从git重新安装它

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

这解决了它.

  • 如果您能提供问题的链接,那就太好了。我知道,时间已经很长了。但这有很大帮助! (2认同)