关于python:nameko-和-peewee-混合使用会影响-TLS-复用数据库连接吗

1次阅读

共计 431 个字符,预计需要花费 2 分钟才能阅读完成。

会得 peewee 用的是 threading.local 来实现 TLS

class _ConnectionLocal(_ConnectionState, threading.local): pass

nameko 并发模型用的是 eventlet 的 pool。解决每个工作的时候,都会创立一个 greenthread,而后提交到 pool 中去跑。

eventlet 的 pool 和 python 的 thread pool 不一样。

python 的 thread pool 是解决 thread 频繁创立和销毁占用资源的问题。所以 python 的 thread pool 是复用线程的。

然而协程的创立和销毁是十分便宜的,所以,没有复用 greenthread 的需要。eventlet 的 pool 不会复用 greenthread。

eventlet 的用法是:创立一个 greenthread,而后提交到 pool 中,跑完了 greenthread 也就被销毁了!那这个 pool 还有什么用呢?我感觉:能够借助 pool 的 size 不便的管制并发数!

正文完
 0