I think you just need to put your recurring method outside of the websocket. I made a gist <https://gist.github.com/s1037989/3ee11ada741db23afe29030da673dee3> that demonstrates that a recurring timer happens ever second and that requests can still be made (L5-6). I think, therefore, that you could put your database calls in that anonymous sub that is currently just spewing a timestamp (L6). Does that make sense? Would that work?
On Mon, Aug 8, 2016 at 10:20 PM, M. Aaron Bossert <[email protected]> wrote: > Ladies and Gents, > > I have been working on an application that incorporates a web socket > route. The web socket route starts up a Mojo::IOLoop->recurring that polls > a database for changes. The web socket works just fine...no issues there, > but it occurs to me that if I have a lot of web socket clients accessing > this route, that essentially, I am polling the database every few seconds > for each of the clients, which seems to be rather wasteful...also, not very > scalable. Sure a dozen clients won't hurt my database, but what if I had a > couple of hundred of them? > > Is there a way to do the database polling in a single loop that then sends > the notification out to all connected web socket clients? Does this need > to be set up as an entirely other application that does the polling and > then have the web socket route listen for messages from it? Or am I > overcomplicating this horribly? > > Aaron > > -- > 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. > -- 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.
