Giter Club home page Giter Club logo

Comments (2)

jcuga avatar jcuga commented on May 12, 2024

Although I have not spent a whole lot of time rigorously profiling the library, anecdotally it seems to perform very well. A large (1000+) number of concurrent connections should be no problem since goroutines are generally much lighter in terms of resources than the threads you would see in a longpoll implemented in another language.

In periods of low event activity where most longpoll connections are just waiting until timeout, the resources should be very minimal and a very large number of connections should be absolutely no problem.

As far as scaling up whenever you would hit a resource issue... Yes, I have considered adding a database backend (since currently everything is in-memory). For scaling, you could also consider segmenting the traffic deterministically across mulitple instances so that each instance has it's own separate universe of data. I have done this myself with good results. But depending on what you're doing this may not be a viable solution--but if you can design the data needs up front so it's easy to segment, that works nicely.

I think the bigger benefit of a database backend would actually be for storage. If you stop your go program, any events in the buffer are gone. So in the future I may consider trying to add generic data backend support for both scaling and data retention across restarts.

I have created #10 as a placeholder to work on this. It may be a while before I get around to it tho 😄 (but I will make a priority to work on any bugs of course)

from golongpoll.

jcuga avatar jcuga commented on May 12, 2024

To follow up about current ways you can scale across multiple instances:

You can load balance (via nginx or other webservers) by URL so that all subscription categories of specific types go to the same instance.

So if you have subscriptions for category "user__actions", you could split the traffic modulo the userid. So all url's for even/odd userids go to one of two instances.

/events/user_1_actions   --> instance A  
/events/user_2_actions   --> instance B
/events/user_3_actions   --> instance A
/events/user_4_actions     --> instance B
...

and any url that publishes on one of those subscription category values should also map to the same instance.

/post/action/user_1  --> instance A
/post/action/user_2  --> instance B
/post/action/user_3  --> instance A
/post/action/user_4  --> instance B
...

You can look up specific webserver options to reverse proxy to one of several IPs/addresses based on the URL pattern.

I have personally done this with a game lobby application where all subscription events/actions were segmented modulo the game lobby id so traffic strain was only limited to the per-lobby level. That way, in order to support more game lobbies, I could add more machines and just update the reverse proxy settings in nginx to now point to more machines.

from golongpoll.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.