[Twisted-Python] Why deferToThread is so slow?

Gelin Yan dynamicgl at gmail.com
Fri Jun 3 20:10:36 MDT 2016


>
>
>
> In general, if you're writing performance-sensitive code, you should
> not use deferToThread.  Instead, you should use deferToThreadPool:
>
>
> https://twistedmatrix.com/documents/current/api/twisted.internet.threads.html#deferToThreadPool
>
> That's because the reactor's threadpool, which deferToThread uses,
> also handles things like DNS lookups.  That means other parts of your
> Twisted program will compete with your performance-sensitive code.  To
> ensure that your performance-sensitive code gets the best chance to
> run it should be given its own thread pool, which *only* runs that
> code.  I'll use such a thread pool in my version of your test program.
>
>
>
>
> https://gist.github.com/markrwilliams/2e40ed0fa06a9e653609dd61fd80ca95#file-simple_threadpool-py
>
>
>
>
Hi Mark

     You mentioned deferToThreadPool. I am curious whether the standard
threadpool in multipleprocessing.dummy works with twisted.

Regards

gelin yan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20160604/75ec2dce/attachment-0002.html>


More information about the Twisted-Python mailing list