3 ms·
This formula `pool size = Tn x (Cm - 1) + 1` is really interesting. Any idea how it's derived or what branch of math this is from?
by sudhirj 6y ago
This formula `pool size = Tn x (Cm - 1) + 1` is really interesting. Any idea how it's derived or what branch of math this is from?
- twic 6y agoI think that's just arithmetic. The fundamental idea is that you have enough connections that you can guarantee that at least one thread has all the connections it needs - because if it does, it can proceed, finish, release its connections, and then another thread can pick them up and gets to proceed, etc. If a thread needs Cm connections, then Cm - 1 connections is enough to be one thread short of what you need. If you have Tn threads, then Tn * (Cm - 1) connections lets every thread, in the worst case, be one short of what it needs (if the connections are not evenly distributed, then at least one thread already has as many as it needs). So Tn * (Cm - 1) + 1 connections means that at least one thread definitely has enough connections.
- sudhirj 6y agoAh, ok. Seems clear that this is for a thread requiring C connections simultaneously to get its work done. That would make it a necessary calculation to avoid deadlocks. I don't see this being necessary in a Rails type app where there's usually one connection per request, but if one were using Go, setting a max connections parameter, and then simultaneously checking out more than one connections to do work, there's an easy chance of deadlocks. Will add a section talking about that and this formula.
- twic 6y ago> Seems clear that this is for a thread requiring C connections simultaneously to get its work done. Exactly. As that document says (my emphasis): > The prospect of "pool-locking" has been raised with respect to single actors that acquire many connections. This is largely an application-level issue. Yes, increasing the pool size can alleviate lockups in these scenarios, but we would urge you to examine first what can be done at the application level before enlarging the pool. > Where Tn is the maximum number of threads, and Cm is the maximum number of simultaneous connections held by a single thread. To be honest, i think applications do this are broken ("largely an application-level issue"), so i'm not sure how important it is.