Skip to Main Content
  • Questions
  • To estimate maximum active sessions is reasonable to the approach?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Quanwen.

Asked: November 01, 2021 - 1:37 pm UTC

Last updated: November 10, 2021 - 4:06 am UTC

Version: 11.2.0.4.0

Viewed 1000+ times

You Asked

Hello Connor,

For estimating the maximum active sessions on my oracle database server I did the some work as follows:

(1) Acquiring Average Active sessions (from ASH) & Logic CPUs in Real Time;
(2) Retrieving the current active sessions by running the SQL statement - select count(*) from v$session where status = ‘ACTIVE’;

Via the above two steps I’ve got AAS is 3.66, Logic CPUs are 192, current active sessions are 61.

Thus I am able to estimate the maximum active sessions using the formula: AAS value/Logic CPUs = current active sessions/maximum active sessions. In my case it looks like this, 3.66/192=61/maximum active sessions, so which is 3200. Is it reasonable to this approach?

Best Regards
Quanwen Zhao

and Connor said...

Try this for your second query

SQL> select count(*) from v$session where status = 'ACTIVE';

  COUNT(*)
----------
        77

SQL> select count(*) from v$session where status = 'ACTIVE' and username is not null;

  COUNT(*)
----------
         1



which is probably a better assessment because we always have 60 or so "active" sessions which are just the background processes sitting there waiting for work to do. You'll probably find this figure will be much closer to the 4 you got from ASH


Rating

  (3 ratings)

Comments

Active sessions from ASH is able to include and exclude BACKGROUND processes

Quanwen Zhao, November 04, 2021 - 8:48 am UTC

Nice, active sessions in ASH are able to include/exclude BACKGROUND processes. Here is my code checking AAS and Logic CPUs as below:

-- Active Sessions (in ASH) including BACKGROUND processes in Last 1 Hour.

SET LINESIZE 200
SET PAGESIZE 200

COLUMN sample_time FORMAT a19
COLUMN stat_name   FORMAT a15

ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss';

WITH ash AS
(
  SELECT TRUNC(sample_time, 'mi') sample_time
         -- TO_CHAR(CAST(sample_time AS DATE), 'yyyy-mm-dd hh24:mi') sample_time
       , 'Active Sessions' stat_name
       , ROUND(COUNT(*)/6e1, 2) stat_value
  FROM v$active_session_history
  WHERE session_type IN ('BACKGROUND', 'FOREGROUND')  -- including background processes
  GROUP BY TRUNC(sample_time, 'mi')
           -- TO_CHAR(CAST(sample_time AS DATE), 'yyyy-mm-dd hh24:mi')
  ORDER BY sample_time
)
SELECT * FROM ash
WHERE sample_time >= SYSDATE - INTERVAL '60' MINUTE
;


-- Active Sessions (in ASH) excluding BACKGROUND processes in Last 1 Hour.

SET LINESIZE 200
SET PAGESIZE 200

COLUMN sample_time FORMAT a19
COLUMN stat_name   FORMAT a15

ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss';

WITH ash AS
(
  SELECT TRUNC(sample_time, 'mi') sample_time
         -- TO_CHAR(CAST(sample_time AS DATE), 'yyyy-mm-dd hh24:mi') sample_time
       , 'Active Sessions' stat_name
       , ROUND(COUNT(*)/6e1, 2) stat_value
  FROM v$active_session_history
  WHERE session_type = 'FOREGROUND'  -- excluding background processes
  GROUP BY TRUNC(sample_time, 'mi')
           -- TO_CHAR(CAST(sample_time AS DATE), 'yyyy-mm-dd hh24:mi')
  ORDER BY sample_time
)
SELECT * FROM ash
WHERE sample_time >= SYSDATE - INTERVAL '60' MINUTE
;


By the way I can also check "type = 'USER'",

SQL> select distinct type from v$session;

TYPE
--------------------
USER
BACKGROUND

SQL> select count(*) from v$session where status = 'ACTIVE' and type = 'USER';

COUNT(*)
-----------
                2


Best Regards
Quanwen Zhao

It makes sense to estimate maxiumum concurrent connections.

Quanwen Zhao, November 08, 2021 - 6:39 am UTC

Actually I should go to estimate maximum concurrent connections (instead of maximum active sessions) for my oracle database server to set a sensible value for processes in v$parameter.

So I should sample the average value of AAS, Logic CPUs and concurrent connections during a period of time, and then using the formula (AAS/Logic CPUs = concurrent connections/maximum concurrent connections) to estimate it.

Best Regards
Quanwen Zhao
Connor McDonald
November 09, 2021 - 2:59 am UTC

To estimate total sessions, you should just take max ever concurrent sessions in your database (because if you hit the processes/sessions limit...pretty much thats unhappy users).

You can then use facilities like instance caging, resource manager, profiles etc etc to ensure that you don't exceed the server *capacity*, which is most likely a number much lower than that

PROCESSES in v$parameter

Quanwen Zhao, November 09, 2021 - 4:47 am UTC

I am very sorry, might my question isn't too accurate!

Actually I wanna estimate PROCESSES in v$parameter whose value is probably related to CPU cores I think at least but how many should I set? Because it indicates that it's the maximum concurrent connections on my oracle database server.

Is it the value of current concurrent connections when CPU load on Linux OS is near to the number of Logic CPUs at that moment?

Best Regards
Quanwen Zhao
Connor McDonald
November 10, 2021 - 4:06 am UTC

processes / sessions can be treated similarly.

If you expect 500 sessions connected, then processes could be 500+100 (for background etc)

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.