Pankaj
Pankaj

Reputation: 3664

mybatis POOLED datasource

I'm using myBatis POOLED datasource . Below are the connection pool configuration -

poolMaximumIdleConnections: 5
poolMaximumActiveConnections: 20

I hit the service with 102, 742 request (160 TPS) and got the below metrics by enabling mybatis log-

No of Request: 102,742

No of Created connection: 8,841
No of Checked out connection: 93,901

No of Returned connection: 93,911
No of Closed connection: 8,831

No of Claimed overdue connection: 0
No of bad connection: 0
  1. Why 8,841 connection got created if pool size is 20. Shouldn't it create only 20 connection and reuse from the pool ?
  2. There're 8,841 connection which got created but only 8,831 got closed. Does this mean 10 connection were still open out there - connection leak ?

Upvotes: 3

Views: 3429

Answers (1)

Florian Schaetz
Florian Schaetz

Reputation: 10652

As you can see in the source code, "checking out" a connection means taking it from the idle pool if one is available, see line 375.

If none is availble, the code tries to "create" one (see line 381)

So, checking out means "reuse", which explains the "checked out" number.

Of course, noone lives forever - even old connections don't. So, older connections are typically killed after a while of idle, which means the idle pool shrinks, which then requires new connections if you want some. Which leads to the number of "created" connections.

And no, if in the end, 10 were alive, that can be totally normal. As you can see, 10 connections were not even closed yet, which typically means that something still uses them. Or it could be a bug on your end, hard to say.

Upvotes: 2

Related Questions