wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.21k stars 295 forks source link

push stream long poling cross doamn connection #279

Closed pokal4u closed 4 years ago

pokal4u commented 6 years ago

HI, How can I connect push stream long poling in auto scaling servers? just like cross domain Thanks

wandenberg commented 6 years ago

Hi @pokal4u, your question was not clear to me. Can you clarify it? Giving examples if possible?

pokal4u commented 6 years ago

Hi, We are using auto scaling servers for load balancing, so we don't know how many servers added automatically based on traffic. Long poling and configurations same in all servers

All servers mapping to single domain, and those IPs are different.

Now traffic (users) shared different servers, long poling work only for users connected in same server

Ex: a,b,c connected to Server 1 d,e,f connected to Server2

long poling works for a->b, b->c, a->c and d->e, e->f, d->f only. not for a->f, d->b, etc.

Code: var pushstream = new PushStream({ host: "domain.com", port: window.location.port, modes: "longpolling", secondsAgo:3600
}); try {
pushstream.addChannel('pokal4u');
pushstream.connect(); } catch(e) {};

Still not understand, please let me know I will explain different way.

Thanks

wandenberg commented 6 years ago

Hi, now guess I understood your use case. A few years ago I had the same requirement and the solution was to use a message server like ActiveMQ. When publishing the message it is sent to a topic at the message server and every server with the pushstream would register itself to this topic (using a small client that is responsible for receiving the message and send to nginx). This way, who is publishing the message does not know how many nginx servers exist and all of them will have the same channels/messages, so does not matter where the client will connect it will "see the same". Another solution would be having a pre-connect phase at your client where it would receive a DNS to connect directly to a specific server, instead of a global DNS, like doing a stick session. There is a proposal to solve this internally in the module making the servers connect to each other. But is far to be implemented yet :(

pokal4u commented 6 years ago

HI,

So nginx push stream long poling not supported?

for your solution pleases share any reference links

wandenberg commented 6 years ago

Hi. Long polling is supported by the module, but in a multi-server environment, it requires some extra work. In fact, all methods in multi-server will require you to either, publish the message to all servers or know where the subscriber to the specific message is connected on. If you are already publishing the message on all servers, you are good to go with long polling. If you are publishing the message to the server where you know that the subscriber is, is just ensure that the client connects always to the same server using different DNSs like I mentioned before. If you need more explanation on how to do it, please share how is your system working to be easier to help. Have you done a load test to check if is really necessary to scale already? The module usually supports a huge number of subscribers/messages in a single server. I would be happy to help increase the performance of your system, increasing the performance of the module, but need to know what are the bottlenecks for you.

I will look for the broker implementation I did, but don't know if I still have the code.