Best alternative for client / server polling?

43 views
Skip to first unread message

Miguel Manso

unread,
May 18, 2020, 7:47:21 PM5/18/20
to Mojolicious
Hi there,

Ive a Perl client that fetched some data every 3 seconds and post it to an API. Both client and server are written using mojo. Client uses Mojo::UserAgent to post JSON and server is a Mojolicious app being served with hypnotoad.

I can have dozens of these clients which mean that each of them will be posting data and receiving from the server every 3 secs. I can easily do this using basic post calls but I wonder if there is a better way to achieve the same? Something like keeping connections opened for a period of time while sending and receiving data through the same connection?

Ive seen websockets info but it seems it’s allways oriented to the client being in JavaScript.

Any thoughts on the subject?

Thanks in advance.

Dan Book

unread,
May 18, 2020, 7:49:21 PM5/18/20
to mojol...@googlegroups.com

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/127f7769-222c-4e76-80bf-af36df28a5e0%40googlegroups.com.

Felipe Gasper

unread,
May 18, 2020, 7:59:52 PM5/18/20
to mojol...@googlegroups.com
We’ve had great success deploying WebSocket in lieu of TCP for server-to-server communication. You harness the routing that a web framework like Mojo does for you--so no futzing with firewalls and the like--but you still get the real-time communication that a raw TCP socket would give you. There’s a CLI utility called “websocat” that basically functions as “netcat for WebSocket”, if that’s of use to you.

An alternative technology, if you only need a server-to-client stream, is Server-Sent Events (SSE). It’s basically an open-ended HTTP response, with the client parsing each chunk of that response as it arrives. Most browsers support it via the EventStream object, and I suspect it’d be pretty straightforward to rig up a Mojo SSE client, too. It’s a bit simpler, too, since it follows HTTP semantics. Not as robust, though, as it lacks the close status mechanism that WebSocket provides. (The server basically has to wait until it sees EPIPE/SIGPIPE to know that the client has stopped listening.)

-FG

Miguel Manso

unread,
Jun 2, 2020, 3:39:00 PM6/2/20
to mojol...@googlegroups.com
Hi there,

Thanks for the answer.

My requirements aren't related with browsers... Imagine I've 50 clients polling a server the ask if they need to "sync" themselves. I'm doing this by making every client to do a request to the server asking if they need to sync... this means that every 10 secs, 50 clients make a request asking the same question... If the clientes are 500 instead of 50, you can imagine the number of requests...

I was trying to use the websocket technology (or something similar) to avoid all those requests... I find that having a Mojolicious websocket server and a client (not browser) makes development less clear and more complicated. Thats why I was looking for some sort of different approach for this issue.

Thanks in advance.

--
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...@googlegroups.com.


--
Miguel Manso
Reply all
Reply to author
Forward
0 new messages