Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 February MySQL: Opening and Closing of Database Connection is very costly

MySQL: Opening and Closing of Database Connection is very costly

This article is half-done without your Comment! *** Please share your thoughts via Comment ***


As a Database Professional, we are listening many times that opening and closing a Database Connection is always costly.

every RDBMS products are doing lots of operation in the background to just an open and close Database Connection.

Every Database Connection requires some amount of Memory and CPU utilization. There is N number of different buffer settings for various RDBMS products.


There are also different approaches to manage database connections like Connection pooling, Persistent connections.

In this post, I am showing that how MySQL single connection is costly and how much different buffer it requires for opening and closing a Database connection.

Please note that I am just listing important buffer parameters, we should change the values basis on our requirements and loads of Database server.

MySQL server maintains several buffers for each database connection used for communication, join and sort operations, other manipulations.

read_buffer_size:
We should increase the size of this buffer when each connection requires sequential scan for MyISAM tables.
For other storage engines, it also uses for indexing, bulk insert into partitions and caching the result of nested queries.

join_buffer_size:
When we require getting a faster full join result without adding an index, We should increase the size of join_buffer_size.
The minimum size of the buffer used for plain index scans, range index scan and joins without an index.

sort_buffer_size:
When we require a faster sort operation, we should increase the size of sort_buffer_size.
This buffer is not specific to any storage engine and it applies in a general manner of optimization.
The best way to increase at the session level and it requires a larger size only for that session.

tmp_table_size:
This buffer size is used for internal in-memory temporary tables and this variable does not apply to user-created MEMORY tables.
If you require performing advance GROUP BY queries, You should increase the size of tmp_table_size.

max_heap_table_size:
This variable defines the maximum size for user-created MEMORY tables which are required to grow at certain levels.

net_buffer_length:
This is one of the important variables because each client database connection associated with a connection buffer and result buffer.
A net_buffer_length variable defines the size for this both buffer and dynamically enlarged up to max_allowed_packet bytes as needed.
Whenever we have less memory, we should change the size of this variable.

max_allowed_packet:
Whenever we require to process the big binary string like BLOB column, we should increase the value of this variable.

thread_stack:
This variable defines the stack size for each connection and when we require to execute the complex SQL Statements, we should increase the size of this variable.


Thus all variables require to allocate and deallocate for each and every database connection and now we can multiply the values of this variable with max_connections.

This is very important to know about this all and we should modify require variable based on our requirements.
Be aware before of setting large number max_connections without any estimation.

Feb 28, 2016Anvesh Patel
PostgreSQL: Populate DROP FUNCTION script with the type of ParametersSQL Server: The Awesome TOP clause WITH TIES option
Comments: 2
  1. ramakrishnan
    May 26, 2016 at 5:52 am

    What is meant by memory tables ?

    • Anvesh Patel
      Anvesh Patel
      May 26, 2016 at 6:17 am

      MySQL Memory engine is responsible to store and manage Memory table in which all your data storage in memory only.
      You can visit this related article for more details.
      https://www.dbrnd.com/2015/12/database-theory-what-is-in-memory-database/
      https://www.dbrnd.com/2015/08/the-memory-or-heap-storage-engine-of-mysql/
      https://www.dbrnd.com/2015/08/mysql-temporary-table-vs-memory-table/

Anvesh Patel
Anvesh Patel

Database Engineer

February 28, 2016 MySQLAnvesh Patel, database, Database Connection, database research and development, dbrnd, max_connections, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....