Channels: development issue with multiple daphne workers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Channels: development issue with multiple daphne workers

Zhiyu/Drew Li
Hi there,

I am trying to migrate a tornado project to django channel2. I have moved all essential parts and wired them up in channel. It runs OK in development mode, but in production it seems the multi-daphne worker configuration is causing strange errors.
AttributeError: '_UnixSelectorEventLoop' object has no attribute 'remove_timeout' 
 
I followed instructions on the official doc (https://channels.readthedocs.io/en/latest/deploying.html) to set up supervisor and nginx. But I am still lack of understanding how it works. Cloud you please explain more on the following settings?

# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8000

# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers mysite.asgi:application

# Number of processes to startup, roughly the number of CPUs you have
numprocs=4

Questions:
What is "--fd 0" here? Is "0" the file descriptor for socket  "tcp://localhost:8000" that Nginx is proxying to?
What is "-u /run/daphne/daphne%(process_num)d.sock" then? Why do we need to set up separate socket for each daphne process? Are all the daphne processes already talking to "fd 0"?

My website only works if I change either of the following
A) change to numprocs=1 ;
Or
B) remove "-u /run/daphne/daphne%(process_num)d.sock"

Thanks
Drew


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMmsbU%3D-oPX_yZ7Kx8PmVfjwKJNSSC0hKOEUXyRGztzHogKGzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Channels: development issue with multiple daphne workers

Andrew Godwin-3
I'm not sure why you're getting the  _UnixSelectorEventLoop - that sounds like a Twisted error you should search around for, and make sure you have the right package versions.

--fd 0 should not be needed in that command line, since you're already passing the UNIX socket, I don't remember why it's there.

I suggest you remove fd=0 and see if that then works with multiple processes.

Andrew

On Mon, Nov 26, 2018 at 3:10 PM Zhiyu (Drew) Li <[hidden email]> wrote:
Hi there,

I am trying to migrate a tornado project to django channel2. I have moved all essential parts and wired them up in channel. It runs OK in development mode, but in production it seems the multi-daphne worker configuration is causing strange errors.
AttributeError: '_UnixSelectorEventLoop' object has no attribute 'remove_timeout' 
 
I followed instructions on the official doc (https://channels.readthedocs.io/en/latest/deploying.html) to set up supervisor and nginx. But I am still lack of understanding how it works. Cloud you please explain more on the following settings?

# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8000

# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers mysite.asgi:application

# Number of processes to startup, roughly the number of CPUs you have
numprocs=4

Questions:
What is "--fd 0" here? Is "0" the file descriptor for socket  "tcp://localhost:8000" that Nginx is proxying to?
What is "-u /run/daphne/daphne%(process_num)d.sock" then? Why do we need to set up separate socket for each daphne process? Are all the daphne processes already talking to "fd 0"?

My website only works if I change either of the following
A) change to numprocs=1 ;
Or
B) remove "-u /run/daphne/daphne%(process_num)d.sock"

Thanks
Drew


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMmsbU%3D-oPX_yZ7Kx8PmVfjwKJNSSC0hKOEUXyRGztzHogKGzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFwN1uq88vgWuJDuyrc7o7tEdu1OT%2BU-i6yXZ2JuCEUD2%3DXeiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Channels: development issue with multiple daphne workers

Zhiyu/Drew Li
Thanks Andrew,

I tried removing "--fd 0" but it didnt work. I got 504 time out error no matter numprocs=1 or 4.
Do you know are there any open-source projects that use channel2?  I just want to take a look at their repos as my examples.

Thanks
Drew




On Tuesday, November 27, 2018 at 10:26:16 AM UTC-7, Andrew Godwin wrote:
I'm not sure why you're getting the  _UnixSelectorEventLoop - that sounds like a Twisted error you should search around for, and make sure you have the right package versions.

--fd 0 should not be needed in that command line, since you're already passing the UNIX socket, I don't remember why it's there.

I suggest you remove fd=0 and see if that then works with multiple processes.

Andrew

On Mon, Nov 26, 2018 at 3:10 PM Zhiyu (Drew) Li <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="9tEronAfAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">zyli...@...> wrote:
Hi there,

I am trying to migrate a tornado project to django channel2. I have moved all essential parts and wired them up in channel. It runs OK in development mode, but in production it seems the multi-daphne worker configuration is causing strange errors.
AttributeError: '_UnixSelectorEventLoop' object has no attribute 'remove_timeout' 
 
I followed instructions on the official doc (<a href="https://channels.readthedocs.io/en/latest/deploying.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fchannels.readthedocs.io%2Fen%2Flatest%2Fdeploying.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGjft-XpjcmqLFoE_ynHn2iJBi9HQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fchannels.readthedocs.io%2Fen%2Flatest%2Fdeploying.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGjft-XpjcmqLFoE_ynHn2iJBi9HQ&#39;;return true;">https://channels.readthedocs.io/en/latest/deploying.html) to set up supervisor and nginx. But I am still lack of understanding how it works. Cloud you please explain more on the following settings?

# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8000

# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers mysite.asgi:application

# Number of processes to startup, roughly the number of CPUs you have
numprocs=4

Questions:
What is "--fd 0" here? Is "0" the file descriptor for socket  "tcp://localhost:8000" that Nginx is proxying to?
What is "-u /run/daphne/daphne%(process_num)d.sock" then? Why do we need to set up separate socket for each daphne process? Are all the daphne processes already talking to "fd 0"?

My website only works if I change either of the following
A) change to numprocs=1 ;
Or
B) remove "-u /run/daphne/daphne%(process_num)d.sock"

Thanks
Drew


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="9tEronAfAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="9tEronAfAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/CAMmsbU%3D-oPX_yZ7Kx8PmVfjwKJNSSC0hKOEUXyRGztzHogKGzA%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/CAMmsbU%3D-oPX_yZ7Kx8PmVfjwKJNSSC0hKOEUXyRGztzHogKGzA%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/CAMmsbU%3D-oPX_yZ7Kx8PmVfjwKJNSSC0hKOEUXyRGztzHogKGzA%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/CAMmsbU%3D-oPX_yZ7Kx8PmVfjwKJNSSC0hKOEUXyRGztzHogKGzA%40mail.gmail.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9657cf08-ced0-49d2-ab83-8338ebe1095a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Channels: development issue with multiple daphne workers

Fogmoon
In reply to this post by Zhiyu/Drew Li
Hi Drew,

Do you now totally understand the parameters -u(bind to unix socket) together with --fd(bind to file descriptor) in the command line configure? The document https://channels.readthedocs.io/en/latest/deploying.html has not been updated since you post this question.

I also feel confused about why here use these two binding endpoint together, although I know daphne support it :

# daphne/cli.py
# Build endpoint description strings from (optional) cli arguments
endpoints = build_endpoint_description_strings(
    host=args.host,
    port=args.port,
    unix_socket=args.unix_socket,
    file_descriptor=args.file_descriptor,
)
endpoints = sorted(args.socket_strings + endpoints)

# daphne/server.py
for socket_description in self.endpoints:
    logger.info("Configuring endpoint %s", socket_description)
    ep = serverFromString(reactor, str(socket_description))
    listener = ep.listen(self.http_factory)
    listener.addCallback(self.listen_success)
    listener.addErrback(self.listen_error)
    self.listeners.append(listener)


So, the key point is in which scenario we need to bind multiple endpoints.  I can not find any document about binding multiple endpoints. If @Andrew can give some suggestion or reference will be great appreciate.




在 2018年11月27日星期二 UTC+8上午7:10:13,Zhiyu (Drew) Li写道:
Hi there,

I am trying to migrate a tornado project to django channel2. I have moved all essential parts and wired them up in channel. It runs OK in development mode, but in production it seems the multi-daphne worker configuration is causing strange errors.
AttributeError: '_UnixSelectorEventLoop' object has no attribute 'remove_timeout' 
 
I followed instructions on the official doc (<a href="https://channels.readthedocs.io/en/latest/deploying.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fchannels.readthedocs.io%2Fen%2Flatest%2Fdeploying.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGjft-XpjcmqLFoE_ynHn2iJBi9HQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fchannels.readthedocs.io%2Fen%2Flatest%2Fdeploying.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGjft-XpjcmqLFoE_ynHn2iJBi9HQ&#39;;return true;">https://channels.readthedocs.io/en/latest/deploying.html) to set up supervisor and nginx. But I am still lack of understanding how it works. Cloud you please explain more on the following settings?

# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8000

# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers mysite.asgi:application

# Number of processes to startup, roughly the number of CPUs you have
numprocs=4

Questions:
What is "--fd 0" here? Is "0" the file descriptor for socket  "tcp://localhost:8000" that Nginx is proxying to?
What is "-u /run/daphne/daphne%(process_num)d.sock" then? Why do we need to set up separate socket for each daphne process? Are all the daphne processes already talking to "fd 0"?

My website only works if I change either of the following
A) change to numprocs=1 ;
Or
B) remove "-u /run/daphne/daphne%(process_num)d.sock"

Thanks
Drew


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c1b64960-5b15-45c5-a1a5-30d9b9f2f3a1%40googlegroups.com.