python - too many sse connections hangs the webpage -



python - too many sse connections hangs the webpage -

what limits number of sse(server sent event) connections?

i have been working on project using django/gunicorn/django-sse.

my project works great when limit number of sse connections page (5 works 6 hangs), isnt huge problem cause utilize pagination can limit number per page. prefer able have many like.

my question is: number of connections slowing down, or amount of info beingness transfered?

the first problem think prepare making them share connection sec limit me bit more.

any ideas may be?

edit:

client side js sse code:

function event(url, resource_name, yes, no, audio_in, audio_out, current_draw){ /** * listens events posted server * * useful site understanding server sent events: * http://www.w3.org/tr/eventsource/ */ var source = new eventsource(url); source.addeventlistener("message", function(e) { resettime(resource_name); info = updatestatus(e.data, yes, no, audio_in, audio_out, current_draw); document.getelementbyid(resource_name+"-in").src = data.audio_in_src document.getelementbyid(resource_name+"-in").alt = data.audio_in_alt document.getelementbyid(resource_name+"-out").src = data.audio_out_src document.getelementbyid(resource_name+"-out").alt = data.audio_out_alt document.getelementbyid(resource_name+"-current").innerhtml = data.current_draw + " a" }); }

in views.py

class serversentevent(redisqueueview): def get_redis_channel(self): """ overrides redisqueueview method select channel hear """ homecoming self.kwargs["resource_name"]

in urls.py

urlpatterns = patterns('', url(r'^$', views.resources_page.as_view(), name='resources_page'), url(r'^(?p<resource_name>\w+)/$', views.statuspage.as_view(), name='status_page'), url(r'^(?p<resource_name>\w+)/sse/$', views.serversentevent.as_view(), name='sse'),)

if you're using sync worker gunicorn (the default), can have many concurrent connections server have worker processes.

the sync worker designed cpu-bound tasks, hence recommendation utilize 2n + 1 workers (where n number of cores available). if sse endpoint logical equivalent of this...

while true: msg = "foo" yield msg sleep(1)

...then have i/o-bound view. no matter how much cpu time throw @ block of code, it's designed never end. if utilize django_sse project, what sse view doing.

the solution utilize asynchronous worker class gunicorn. install gevent , pass --worker-class=gevent alternative gunicorn , you're on way asynchronous utopia.

python django gunicorn server-sent-events

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -