Channels: development issue with multiple daphne workers

338 ogledov
Preskoči na prvo neprebrano sporočilo

Zhiyu (Drew) Li

neprebran,
26. nov. 2018, 18:10:1326. 11. 18
do django...@googlegroups.com
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


Andrew Godwin

neprebran,
27. nov. 2018, 12:26:1627. 11. 18
do django...@googlegroups.com
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

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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.

Zhiyu/Drew Li

neprebran,
27. nov. 2018, 15:32:0127. 11. 18
do Django users
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

Fogmoon

neprebran,
19. avg. 2019, 05:21:2619. 8. 19
do Django users
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写道:
Odgovori vsem
Odgovori avtorju
Posreduj
0 novih sporočil