Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database connection expensive to create?

Why is database connection expensive to create ? Like what finite resource (bandwidth/network round trip/cpu) exactly is it consuming ?

Typically expensive to create means it is consuming some resource like cpu/disk/io, but in case of connection i can only think of the time it takes for Sync/Ack etc.

like image 884
JavaDeveloper Avatar asked Dec 16 '15 03:12

JavaDeveloper


People also ask

Why database connection is expensive?

Database connections are much more than just a TCP/IP socket. Each connection consumes memory that associates the user with various resources in the database. It will likely use up some memory blocks from a shared memory pool, etc.

How many database connections do I need?

In general, the number of max connections should be equal to the number of requests you expect the web server to perform each second. This will depend on how heavy your database logic is. For a new deployment, something around 15 as the value of max connections should be OK.

How long does it take to connect to a database?

Depending on the DB instance class and the amount of storage, it can take up to 20 minutes before the new instance is available.


Video Answer


1 Answers

You didn't say what database you are asking about, so this answer is pretty generic.

Database connections are much more than just a TCP/IP socket. Each connection consumes memory that associates the user with various resources in the database. It will likely use up some memory blocks from a shared memory pool, etc. Just authorizing the connection will run several queries, depending on the connection string. First the user will be authenticated. If an "initial-catalog" is specified, then an authorization will be performed as well. And if there is some sort of auditing going on, then the connection will be logged somewhere.

like image 79
Tim Mc Avatar answered Sep 29 '22 11:09

Tim Mc