4 ms·
Unfortunately this approach precludes GIL languages like Python. If you're able to use a language/runtime that is amenable to multithreading, then using a threa
by throwaway894345 7y ago
Unfortunately this approach precludes GIL languages like Python. If you're able to use a language/runtime that is amenable to multithreading, then using a thread per connection works fine for most use cases (and it's probably easier than using whatever async/await interface your language has).
- th0ma5 7y agoTrue that the GIL prevents the specific expressed pattern you're talking about, but many have been able to do multiple threads and processes with Python itself and also things like gunicorn or uwsgi.
- throwaway894345 7y agoYes, but I was responding to the article which was describing alternative patterns besides wsgi.
- pmoleri 7y ago> probably easier than using whatever async/await interface your language has Is it? I haven't used threads directly in a while, but I remember dealing with sinchronization issues. Problems that just don't exist in single threaded node with async await. I find the async Promise or Task to be a more useful abstraction than the thread. Although, you need threads or a task dispatcher with a pool of threads if you need to run cpu intensive stuff.
- throwaway894345 7y agoIf you’re just handling requests there isn’t much for shared state, so you don’t have to worry about synchronization.
- pdonis 7y ago> If you’re just handling requests there isn’t much for shared state No, but if your single listener/server thread is managing epoll for all your file descriptors, you do have to have a way of synchronizing the worker threads with it, so they know when and when not to read from/write to their fd's. I assume Rachel is using some kind of semaphore or other threading synchronization mechanism for this.
- throwaway894345 7y agoRight, there is some shared state, but it’s very minimal.