Oracle-DB: Cost of dedicated DB session connect/disconnect

 A generally assessed poor technique is to create an own dedicated database session for each atomic DB activity.

You may sometimes encounter such strategies like:

  • processing a large amount of items in a loop, each processing step in the loop creates a DB session, executes a small set of SQL statements and terminates the session
  • a polling process checks a SQL result one time a second, each in a new DB session
But what costs are generated by frequently connecting and disconnecting DB session?

The internal recording of database activity (AWR/ASH) has no answer because establishing the DB connection is not a SQL activity.

A simple comparison of system load gives a fuzzy hint to the price of connection creation.

Example:
  • An idle database instance on a single host with 4 older CPU cores (Intel Xeon E312xx, 2,6 GHz)
  • an external (not on DB host) SQLPlus client which executes a single "SELECT SYSTIMESTMP FROM DUAL" per DB session
  • Delay between the SQLPlus calls is calculated so that one connection per second is created and destroyed.
  • 6 Threads active each with one session creation per second
Result:
  • with idle database CPU load over 4 CPU nodes is in average 0.22%
  • with 6 threads creating and destroying sessions each second CPU load is 6.09%
  • additional io wait also occurs with 1.07% in average
  • so in average 5.87% of 4 CPU nodes are allocated by this 6 threads
  • Equivalent to 23.48% of one CPU node for 6 threads or 3,91% per thread
That means:
Connecting and disconnecting an dedicated Oracle DB session once per second costs approximately 4% of a CPU core of DB server.

This value in mind should help to consider if it's worth to change process behavior regarding DB session creation or not.
Solutions for that issue are to hold the DB connection over the lifetime of the application instance or use the various types of connection pools at client or server side.


Comments

Popular posts from this blog

Oracle-DB: How to check for appropriate sequence caching

Common pitfalls using SQL*Net via Firewalls

Oracle-DB: Identify excessive logon/logoff operations with short-running sessions