Magnus Ahltorp的Mysql Driver裏面介紹emysql的缺陷:mysql
1. 隔離不夠好,git
2.不能伸縮github
mysql-otp使用1個進程1個mysql鏈接,隔離得很好。推薦使用。sql
mysql-otp-poolboy 使用poolboy + erlang-otp 來造成線程池,使用poolboy來避免線程數量不足或者過多的狀況。ui
參考:which erlang's pool is suitable?spa
poolboy automatically reduces workers when there is not work for them.
You get a worker to do some work with checkout from the pool, and you release the worker with checking, as an alternative, you enclose the work on transaction which automatically checkouts the worker and after its done it checkins the worker.
When you start the pool, poolboy automatically creates a number of size workers, waiting to handle some work.
When you call checkout, poolboy tries to get one of the workers which is already started, if all of the workers are already checkout because they are doing some work, it checks its max_overflow configuration and it starts to create workers to handle the load until it reaches max_overflow.
When a worker is released, if there are not more jobs for the workers, they are killed.
So if you create a pool like
{pool, [
{size, 100},
{max_overflow, 900}
]}
size代表最少進程池的數量,max_overflow代表若是進程池沒有空閒進程,則最多新開多少個進程數量。.net
推薦使用mysql-otp-poolboy。線程