<html><head><base href="x-msg://527/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 17, 2009, at 7:40 PM, Alex Gentle wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">&gt;Once you have parsed the message from socket server and determined it &gt;should go to rabbit, you publish the message to it. </pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">&nbsp;</pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">I don�t know Ruby. I wrote a PHP program that parse the message from socket server and pass the message to RabbitMQ server.</pre></div></span></blockquote><div><br></div><div><br></div><div>I wrote the examples in ruby since the code is very compact. You can perform the same operations in any language that has an AMQP library.</div><div><br></div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">The catch here is the performance. iPhone needs to query for the message in the queue every few seconds. </pre></div></span></blockquote><div><br></div><div><br></div><div>I think we are getting ahead of ourselves. Your original post indicated that your code did not work but now you are worried about performance. Let's get your code working first and then you can worry about optimizing it later.</div><div><br></div><div>Can you successfully publish your messages yet? If so, can you pop them off of the queue to read them?</div><div><br></div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">Let us assume </pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">
that User A and User B chats thru iPhone application. User A sends the message to RabbitMQ. </pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">&nbsp;</pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">User A -&gt; Socket Server -&gt; RabbitMQ Server</pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">&nbsp;</pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">RabbitMQ has no way of sending the notification to User B that some message is waiting for him. </pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">&nbsp;</pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">User B needs to check the RabbitMQ server every 5 seconds to see if there is any message in his queue. </pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">&nbsp;</pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">Imagine there are 10,000 users like user A and B. All of them will be sending the message thru socket server to RabbitMQ server. Socket <br>
server can handle all the traffic. It�s a piece of cake for RabbitMQ to handle the traffic. But, the poor PHP program in the middle <br>(between socket server and RabbitMQ) can�t handle all the incoming and outgoing requests with ease. It�s going to slow down the process. <br>
Users will see substantial delay in sending and receiving messages. </pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">&nbsp;</pre><pre style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: 'Courier New'; ">Is there a better way to do it? Thanks.</pre></div></span></blockquote><br></div><div>Polling is usually a bad idea particularly since it requires a lot of unnecessary messaging. Most AMQP libraries I have seen allow for two ways to fetch messages. One way is to "get" them from the queue which is a synchronous operation. The second way is to "subscribe" to a queue and have it asynchronously push messages to the subscriber. You want to investigate this second methodology for your application. Async operations result in slightly more complex code but they will let you scale better than polling/synchronous operations.</div><div><br></div><div>cr</div><div><br></div></body></html>