How do you configure Stash to not open as many DB connections?

Stash seems to open about 20 DB connections on startup. How can this be lowered to a more reasonable number. I am running Stash 2.2 and 2.3.

2 answers

1 accepted

7 votes
Accepted answer
Bryan Turner Atlassian Team Apr 09, 2013


I'm one of the Stash developers. As noted by Daniel, Stash by default idles with 16 connections, in 4 pools of 4 connections, and may create up to 80 connections maximum (20 connections in 4 pools). Stash uses multiple pools to reduce lock contention around acquiring connections, which improves its performance when under heavy load. Stash provides a lot of different knobs for adjusting how it uses the database. These can all be overridden in For each property I list below I show the value it has by default.

db.pool.partition.count=4 : This setting controls how many pools Stash uses, with a minimum of 1. Lower values will open fewer connections, but will have increased contention for acquiring connections.

db.pool.partition.connection.maximum=20 : For each parition, this controls the maxmimum number of connections allowed. That means the absolute maximum is db.pool.partition.count times this value.

db.pool.partition.connection.minimum=4 : For each partition, this controls the minimum number of connections that are kept open at all times. Stash will heartbeat these connections to prevent them from idling out. That means the absolute minimum is db.pool.partition.count times this value.

Adjusting the minimum and maximum may also require adjusting:

db.pool.acquireIncrement=2 : When a pool approaches exhaustion, if it currently has fewer connections open than the maximum allowed, this controls the number of connections opened and added to the pool.

db.pool.partition.connection.threshold=10 : When the number of open, free connections in a pool drops to or below this threshold, as a percentage of the maximum, new connections will automatically be opened. When adjusting the minimum and maximum, be careful to ensure the minimum exceeds this threshold. For example, if you lower the minimum to 1 and leave the maximum at 20, 1 is not 10% of 20, so the system will automatically open acquireIncrement more connections until the threshold is exceeded. This threshold is strictly greater than, so a minimum of 1 and a maximum of 10 will also trigger immediately opening additional connections.

Lastly, for heartbeating, Stash provides the following:

db.pool.idle.maxAge=30 : Defines the number of minutes a connection is allowed to remain open before it is closed, down to the configured minimum for each pool.

db.pool.idle.testInterval=10 : Defines the number of minutes a connection is allowed to be idle before a simpe test SQL statement is automatically run on it to prevent the connection from timing out. These heartbeat connections do not reset the maxAge counter; they just prevent the RDBMS server from closing connections out from under Stash.

Stash's database pooling is provided by BoneCP, if you'd like to read more about how it works.

Hope this helps,
Bryan Turner
Atlassian Stash

0 votes
Daniel Rohan Atlassian Team Apr 09, 2013

Hello Bob,

By default, Stash is designed to idle with this many connections. Is there a reason you don't consider this reasonable? We have a set of properties to ultimately reduce the number of connections but I'm checking to see if there are any ramifications to reducing this number.



It is because I run multiple servers for testing.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

211 views 3 7
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you