On Friday, February 24, 2017 at 10:40:08 PM UTC, sri wrote:
>
>          for (1..10000) {
>>            $sc->{websocket}->send({text => $payload});
>>          }
>>
>
> This is fundamentally flawed code. All your're doing here is building 
> 10000 websocket
> frames and appending them one by one to a write buffer. No actual I/O is 
> performed here and
> lots of time wasted that could be spent doingother stuff concurrently.
>
>
Hi,

Thanks for the reply. The above code is to highlight the 'problem', but I 
certainly accept that I could be doing something wrong and this isn't a 
problem at all:)

Flipping the question around slightly, if I know I've got 10000 messages 
sitting in an event queue that needs to be sent to a websocket, how should 
I do it with out causing this CPU spike? Should I call one_tick or 
something similar?

To give a little more information, I'm using an incoming socket to notify 
me that there is (at least one) event to be handled in a thread safe event 
queue, then in my event handler I have something like this (pseudo code):

sub EventHandler {
  while ($eventQueue->HasMessages) {
    my ($messageCode,$messageObject) = $eventQueue->GetMessage();
      if ($messageCode == 12) {
         #in reality we would have multiple websockets here
         $websocket->send({text => $messageObject});
      }
  }
}

Regards,


-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to