It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Answer accepted
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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,617 views 2 18
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you