亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何理解 Tornado 官方關于并發的一條建議

如何理解 Tornado 官方關于并發的一條建議

泛舟湖上清波郎朗 2018-10-10 12:29:52
查看完整描述

1 回答

?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

In general, you should think about IO strategies for tornado apps in this order:

1) Use an async library if available (e.g. AsyncHTTPClient instead of requests).

2) Make it so fast you don't mind doing it synchronously and blocking the IOLoop. This is most appropriate for things like memcache and database queries that are under your control and should always be fast. If it's not fast, make it fast by adding the appropriate indexes to the database, etc.

3) Do the work in a ThreadPoolExecutor. Remember that worker threads cannot access the IOLoop (even indirectly) so you must return to the main thread before writing any responses.

4) Move the work out of the tornado process. If you're sending email, for example, just write it to the database and let another process (whose latency doesn't matter) read from the queue and do the actual sending.

5) Block the IOLoop anyway. This is the lazy way out but may be acceptable in some cases.
查看完整回答
反對 回復 2018-10-24
  • 1 回答
  • 0 關注
  • 784 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號