[Mojolicious] Re: mojo using 100% CPU

2017-02-25 Thread jez_white


On Friday, February 24, 2017 at 10:40:08 PM UTC, sri wrote:
>
>  for (1..1) {
>>$sc->{websocket}->send({text => $payload});
>>  }
>>
>
> This is fundamentally flawed code. All your're doing here is building 
> 1 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 1 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 mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Integrating to other event based event based architectures

2017-02-10 Thread jez_white
Hi,

Thanks for the reply. I managed to get something working using:

Mojo::IOLoop->client

I know it will be a stupid question...but how to do get access to the 
reactor object? The docs give examples like:

$loop->reactor

Initially I thought I could do, Mojo::IOLoop->reactor but that doesn't 
work, so do how do you get the Mojo::IOLoop object into a variable?

Regards,
 
On Thursday, February 9, 2017 at 12:03:40 PM UTC, sri wrote:
>
> Just use the reactor directly. 
>
> http://mojolicious.org/perldoc/Mojo/IOLoop#reactor 
>
> -- 
> sebastian 
>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Integrating to other event based event based architectures

2017-02-09 Thread jez_white
All,

I'm currently playing with mojolicious for a prototype project and I like 
what I see. Apologies if my terminology is off, I'm still learning mojo:)

I've started to explore the idea of using mojo to replace some of our 
legacy embedded web based technologies and for a future embedded REST API, 
but I am struggling with how to integrate it to our event based back end. 
Specifically on how to generate an event from within Mojo::IOLoop. I know I 
can use a timer based approach, ie, wake up every second to see if an event 
has arrived, but it's not ideal for various reasons. 

The application itself is a C/XS based, and spawns a thread that runs perl 
code to provide a web based UI and API to monitor/control the application. 
 Some of the older stuff is based on HTTP::Daemon  while some of the newer 
stuff handles websockets based on Protocol::WebSocket so it's all low level 
and mojolicious would excel as a replacement.

Many of the requests would block for a variety of reasons (ie, the response 
takes time) and the way we handle this is to have the perl code sitting on 
a select (IO::Select) statement which handles the raw websocket connection 
and a socket connection from inside our app. If a message is received on 
this app socket, we then read from our event message queue, process it and 
send it down the websocket. For the most part, this works well and results 
in mostly none blocking operation.

I believe I can use the same approach of using a socket from the thread 
running mojo to the app, but I am unsure how to create this socket and 
associated it to Mojo::IOLoop to get callbacks etc?

Is this raw socket approach the best solution, or are there other ways to 
get Mojo::IOLoop to wake up on an 'external event'? 

Thanks,

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.