Ich habe dieses Python-Skript, das als RPC-Server fungiert, indem Sie das Standard-RPC-Beispiel in RabbitMQ Tutorial gefunden here. Es läuft gut in meinem Laptop. Aber wenn ich laufe es in einer Amazon EC2 hohen CPU-Medium Instanz mit diesen Spezifikationen:RabbitMQ Python-Worker-Skript mit 100% CPU
1,7 GiB Speicher
5 EC2 Compute Units (2 virtuelle Kerne mit 2,5 EC2 Compute Units je)
350 GB Instanzenspeicher
Es dauert 100% CPU. Obwohl mein Laptop mit fast der gleichen Konfiguration dies mit weniger als 4% CPU-Auslastung ausführt. Ich führe dies in Ubuntu-12.04 sowohl auf meinem Laptop als auch auf Amazon aus.
Hier ist mein 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()
Wie kann ich dieses Problem beheben?
Es wäre toll, wenn Sie einen Link zum Problem bereitstellen können. Ich weiß, es ist eine sehr lange Zeit. aber es hilft sehr! –
@HariKrishnan das ist der Bug https://github.com/pika/pika/issues/361 –