Comments (2)
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
from golongpoll.
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)
- add data backend for scaling and data persistence support HOT 2
- Listen on multiple categories HOT 1
- Do you have an example on how to create a reliable http client to consume golongpoll?
- Offer an "official" Golang client HOT 2
- High CPU load? HOT 5
- client js HOT 3
- Events published in same millisecond aren't seen by clients HOT 3
- how to delete buffer after certain time? HOT 18
- Please replace deprecated CloseNotify with Context().Done() HOT 3
- question: version migration guide HOT 2
- How do you make sure the concurrent issue? HOT 2
- Gin framework support HOT 7
- multiple replicas problem HOT 4
- Acks every 15 seconds HOT 1
- Return timestamp in timeout response HOT 5
- Handler keeps on waiting for a timeout even though the client has been disconnected. HOT 5
- question about Http Server integration HOT 5
- Latest tag name seems like a typo - messes up SemVer HOT 2
- used in production? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from golongpoll.