Magnus Ahltorp的Mysql Driver里面介绍emysql的缺陷:
1. 隔离不够好,
2.不能伸缩
mysql-otp使用1个进程1个mysql连接,隔离得很好。推荐使用。
mysql-otp-poolboy 使用poolboy + erlang-otp 来形成线程池,使用poolboy来避免线程数量不足或者过多的情况。
参考:which erlang's pool is suitable?
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表明如果进程池没有空闲进程,则最多新开多少个进程数量。
推荐使用mysql-otp-poolboy。