<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix"><br>
php-amqplib was first solution we used. However, we had to switch
to AMQP extension because connecting was very slow :( It took
minimum 50ms for php-amqplib to establish connection to RabbitMQ.
Most of this time was spent on fread call. AMQP extension also
uses a lot of time for connection, but much less than php-amqplib
(up to 20ms).<br>
<br>
We're not using basic_consume, since we must monitor two different
channels/exchanges (one direct and one fannout). This is because
workers must get messages (task related) by direct queue, and
broadcasts over fannout. That's why we used code from one of
examples:<br>
<br>
<i> while (count($ch->callbacks)) {</i><i><br>
</i><i> $read = array($conn->getSocket()); // add here
other sockets that you need to attend</i><i><br>
</i><i> $write = null;</i><i><br>
</i><i> $except = null;</i><i><br>
</i><i> $num_changed_streams = stream_select($read, $write,
$except, rand(10,15));</i><i><br>
</i><i><br>
</i><i> ....</i><i><br>
</i><i> }</i><br>
<br>
This is where php-amqplib is much better than AMQP extension :(
Since AMQP extension doesn't have (or we didn't find example) that
can wait on stream for predefined number of seconds, and then
return control back to PHP script, like <i>stream_select </i>does.
<br>
<br>
So, on end, we ended up using AMQP extension for producers and
php-amqplib for consumers ... crazy isn't it?<br>
<br>
On 05/19/2013 04:28 PM, Alvaro Videla wrote:<br>
</div>
<blockquote
cite="mid:CAMcAHLUmH2rrb6QuZX84Z-pvXwvVnixprKFGKevC3zXHso8AjA@mail.gmail.com"
type="cite">
<div dir="ltr">Hi,
<div><br>
</div>
<div>The php-amqplib from here <a moz-do-not-send="true"
href="https://github.com/videlalvaro/php-amqplib">https://github.com/videlalvaro/php-amqplib</a>
can easily publish 4000 msgs in 1.5 seconds and it can consume
them in about the same time, using just 1 producer and 1
consumer.</div>
<div><br>
</div>
<div style="">Is worth noting that the consumers in the
benchmark code are doing a <span
style="color:rgb(0,128,128);font-family:Consolas,'Liberation
Mono',Courier,monospace;font-size:12px;line-height:18px;white-space:pre">basic_consume</span> on
the queue and not a basic_get. The benchmark code can be
easily run if you check out the library form Github and run <b>make
benchmark</b>.</div>
<div><br>
</div>
<div style="">I think the problem you have on the producing side
is the way PHP work, where sharing resources is not so easy
due to the script state being cleaned after every request,
thus the need of opening one connection per request.</div>
<div style=""><br>
</div>
<div style="">Regarding persisting connections with PHP, while
the socket connection to RabbitMQ could be persisted across
requests, what do we do about channels and
the whole connection state? With PHP this is not so easy to
solve.</div>
<div style=""><br>
</div>
<div style="">If you need to achieve max speed from your
publishing side I would consider using a REST endpoint as
someone suggested already.</div>
<div style=""><br>
</div>
<div style="">On the other hand if your concern regarding
publishing speed is to not make the users wait for the request
to finish, then keep in mind that php-fpm has a function
called <span
style="color:rgb(68,68,68);font-family:arial,sans-serif;line-height:17.77777862548828px">fastcgi_finish_request.
You can call it at the end of your script and then send the
messages to RabbitMQ.</span></div>
<div style=""><span
style="color:rgb(68,68,68);font-family:arial,sans-serif;line-height:17.77777862548828px"><br>
</span></div>
<div style=""><span
style="color:rgb(68,68,68);font-family:arial,sans-serif;line-height:17.77777862548828px">Regards,</span></div>
<div style=""><span
style="color:rgb(68,68,68);font-family:arial,sans-serif;line-height:17.77777862548828px"><br>
</span></div>
<div style=""><span
style="color:rgb(68,68,68);font-family:arial,sans-serif;line-height:17.77777862548828px">Alvaro</span></div>
<div style=""><br>
</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Sun, May 19, 2013 at 4:11 PM, Nikola
Savic <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:niks@osic.rs" target="_blank">niks@osic.rs</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div><br>
Consumers are not restarting ... producers are. Every
page request is new execution of PHP script, which must
open new connection when trying to send first message,
and close it when it finishes.
<div>
<div class="h5"><br>
<br>
On 05/19/2013 04:08 PM, Michael Klishin wrote:<br>
</div>
</div>
</div>
<blockquote type="cite">
<div>
<div class="h5">
<div dir="ltr">
<div class="gmail_extra"><br>
<div class="gmail_quote">2013/5/19 Nikola Savic
<span dir="ltr"><<a moz-do-not-send="true"
href="mailto:niks@osic.rs" target="_blank">niks@osic.rs</a>></span><br>
<blockquote class="gmail_quote"
style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex"> Yes ... it's
the same app which postpones execution of
some actions using MQ.</blockquote>
</div>
<br>
Then cluster won't solve your problem because
the issue is not node delivery rate.<br>
<br>
You need to avoid constant restarts and
reconnections for your consumers or simply</div>
<div class="gmail_extra">increase their number
and/or throughput.<br>
-- <br>
MK<br>
<br>
<a moz-do-not-send="true"
href="http://github.com/michaelklishin"
target="_blank">http://github.com/michaelklishin</a><br>
<a moz-do-not-send="true"
href="http://twitter.com/michaelklishin"
target="_blank">http://twitter.com/michaelklishin</a><br>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div>
</div>
<div class="im">
<pre>_______________________________________________
rabbitmq-discuss mailing list
<a moz-do-not-send="true" href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.rabbitmq.com</a>
<a moz-do-not-send="true" href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a>
</pre>
</div>
</blockquote>
<br>
</div>
<br>
_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a moz-do-not-send="true"
href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a moz-do-not-send="true"
href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss"
target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
rabbitmq-discuss mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a>
<a class="moz-txt-link-freetext" href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a>
</pre>
</blockquote>
<br>
</body>
</html>