Sunday, March 17, 2019

Evaluate the shared server vs dedicated server execution differences on a concurrent job situation

Lab objective: Evaluate the shared server vs dedicated server execution differences on a concurrent job situation

This time, we have to spawn 10 connections concurrently in dedicated & in shared mode.

Queries to be used for this excercise:

To monitor the pga/uga per group of connection:

---monitor_pgauga.sql

set lines 300
set pages 3000
set feedback off
select c.server,a.name,count(c.sid),sum(b.value)
from v$statname a, v$sesstat b,v$session c
where c.username='SCOTT'
and b.sid=c.sid
and a.statistic#=b.statistic#
and lower(a.name) in ('session uga memory','session uga memory max','session pga memory','session pga memory max')
group by c.server,a.name
order by 1,2;
exit;


---ugaexamination_lab.sql

set term off
select a.owner,a.object_id,b.object_name
from dba_objects a,dba_objects b
where a.object_id=b.object_id
and a.object_id > 10000;
dbms_lock.sleep(1);
select a.owner,a.object_id,b.object_name
from dba_objects a,dba_objects b
where a.object_id=b.object_id
and a.object_id > 10000;
dbms_lock.sleep(1);
select a.owner,a.object_id,b.object_name
from dba_objects a,dba_objects b
where a.object_id=b.object_id
and a.object_id > 10000;
exit;


---- shell script to generate the workload of dedicated connection

##wrapper_launch_dedicated_conn.sh
#!/bin/ksh
export ORAENV_ASK=NO
. oraenv testinst
sqlplus -s '/as sysdba' @create_snap.sql
i=1
while [[ $i -le $1 ]];
do
dt=`date +%d%m%y_%H%M%S`
sqlplus -s scott/<PWD>@oraded @ugaexamination_lab.sql &
(( i++ ))
done
statprcnt=`ps -ef|grep -i sqlplus|grep -i ugaexamination_lab.sql|wc -l`
while [[ ${statprcnt} -gt 0 ]];
do
sleep 3
statprcnt=`ps -ef|grep -i sqlplus|grep -i ugaexamination_lab.sql|wc -l`
done
sqlplus -s '/as sysdba' @create_snap.sql
exit


---- shell script to monitor the pga/uga utilisation

###monitor_pgauga.sh
#!/bin.ksh
export ORAENV_ASK=NO
. oraenv testinst
while :
do
echo "###################"
dt=`date +%d%m%y_%H%M%S`
echo "zzzzzz $dt"
sqlplus -s '/as sysdba' @monitor_pgauga.sql
dt1=`date +%d%m%y_%H%M%S`
echo "$dt1: going to sleep rountine 1 for 1 secs.. press ctrl+c here if you intend to kill the script"
sleep 1
dt2=`date +%d%m%y_%H%M%S`
echo "$dt2: going to sleep rountine 1 for 1 secs.."
sleep 1
done



---- shell script to generate the workload of shared connection

##wrapper_launch_shared_conn.sh
#!/bin/ksh
export ORAENV_ASK=NO
. oraenv testinst
sqlplus -s '/as sysdba' @create_snap.sql
i=1
while [[ $i -le $1 ]];
do
dt=`date +%d%m%y_%H%M%S`
sqlplus -s scott/<PWD>@orashared @ugaexamination_lab.sql &
(( i++ ))
done
statprcnt=`ps -ef|grep -i sqlplus|grep -i ugaexamination_lab.sql|wc -l`
while [[ ${statprcnt} -gt 0 ]];
do
sleep 3
statprcnt=`ps -ef|grep -i sqlplus|grep -i ugaexamination_lab.sql|wc -l`
done
sqlplus -s '/as sysdba' @create_snap.sql
exit


===> Round 1, launch the below shell scripts for dedicated connection test.

screen 1:
./monitor_pgauga.sh

example output:
###################
zzzzzz 170319_205801
170319_205801: going to sleep rountine 1 for 1 secs.. press ctrl+c here if you intend to kill the script
170319_205802: going to sleep rountine 1 for 1 secs..
###################
zzzzzz 170319_205804

SERVER    NAME                                                             COUNT(C.SID) SUM(B.VALUE)
--------- ---------------------------------------------------------------- ------------ ------------
DEDICATED session pga memory                                                         10     13941264
DEDICATED session pga memory max                                                     10     14400016
DEDICATED session uga memory                                                         10      3375896
DEDICATED session uga memory max                                                     10      4015872
170319_205804: going to sleep rountine 1 for 1 secs.. press ctrl+c here if you intend to kill the script
170319_205805: going to sleep rountine 1 for 1 secs..
###################



screen 2:
./wrapper_launch_dedicated_conn.sh 10

example output:
##################
The Oracle base has been set to /u01/app/oracle

PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.

[oracle@host testdir]$


===> Bounce the DB

===> Round 2, lauch the below shell scripts for shared server connection test.
screen 1:

./monitor_pgauga.sh

170319_212839: going to sleep rountine 1 for 1 secs..
###################
zzzzzz 170319_212840

SERVER    NAME                                                             COUNT(C.SID) SUM(B.VALUE)
--------- ---------------------------------------------------------------- ------------ ------------
SHARED    session pga memory                                                          7     47667512
SHARED    session pga memory max                                                      7     52927448
SHARED    session uga memory                                                          7      8654272
SHARED    session uga memory max                                                      7      8760544
170319_212841: going to sleep rountine 1 for 1 secs.. press ctrl+c here if you intend to kill the script
170319_212842: going to sleep rountine 1 for 1 secs..
###################



screen 2:

./wrapper_launch_shared_conn.sh 10

example output:
The Oracle base has been set to /u01/app/oracle

PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.

[oracle@host testdir]$


Differences:

Fact 1 ) Examine session response time:

Dedicated conn lasted for : 170319_205804 to 170319_205954 [until the last connection exited] => 110 seconds
Shared conn lasted for : 170319_212624 to 170319_212921  [until the last connection exited] => 177 seconds

So there is about 67 seconds latency on shared server.

Fact 2) Examine memory utilisation:
Dedicated: [last but 1 snap view - when all 10 connections were active] - here the uga resides in pga

SERVER    NAME                                                             COUNT(C.SID) SUM(B.VALUE)
--------- ---------------------------------------------------------------- ------------ ------------
DEDICATED session pga memory                                                         10    111852048
DEDICATED session pga memory max                                                     10    116111888
DEDICATED session uga memory                                                         10    101117584
DEDICATED session uga memory max                                                     10    101264424


So overall PGA use is 110.73 MB.

Shared: [last snap with 10 conn view]

SERVER    NAME                                                             COUNT(C.SID) SUM(B.VALUE)
--------- ---------------------------------------------------------------- ------------ ------------
SHARED    session pga memory                                                         10     69367664
SHARED    session pga memory max                                                     10     78215024
SHARED    session uga memory                                                         10     12713760
SHARED    session uga memory max                                                     10     12814800


If we observe above
pga max: 78215024
uga max: 12814800
total: 86.81 MB

So we save about 23.9 MB in shared server vs dedicated server. Not sure if we increase the connection, we will have this difference increase as well. Though I took awr snaps, I noticed the current shell's environment variables ruined my snapshots (though the test is valid), hence I am not able to figure out which subpool in shared pool catered to shared server connection.

Thanks

Sunday, March 10, 2019

Examine pga usage for dedicated vs shared server connection

Lab objective: examine pga usage for dedicated vs shared server connection

concept guide:  [read it once before proceeding to this blog]
https://docs.oracle.com/database/121/CNCPT/memory.htm#CNCPT7776
https://docs.oracle.com/database/121/TGDBA/tune_pga.htm#TGDBA347

Snipet of understandings:
UGA part of pga - user session memory, the session memory which must be available for the duration of the session.

Shared server:
UGA will be located in SGA [this includes session memory,persistent area and runtime area for select,since the doc says dml/ddl runtime goes to pga)

Dedicated server:
UGA will be in PGA

SQL work area part of pga, such as sort area,hash area,bitmap merge area all stay in the pga irrespective of the type of connection.

Setup:
1) Follow previous blog on shared server setup [http://oracledbaplanner.blogspot.com/2019/01/configure-shared-server-on-oracle-121.html]
2) Frame a query and get ready to dump the heapdump for pga for the session we ran this query

select a.owner,a.object_id,b.object_name
from dba_objects a,dba_objects b
where a.object_id=b.object_id
and a.object_id > 10000;

3) question, how will you dump heap dump for a shared server connection, since it mightnt have any process associated with it. We have to dump the heapdump from the same session (such that a shared server will pick it up) where we are running this sql. To keep this simple, let us do the heapdump for both the dedicated and shared server connection from the same session and observe how they are different.
Queries to be used:

col server for a10
col service_name for a12
col username for a9
col program for a45
col module for a15
set lines 300
set pages 3000
alter session set nls_date_Format='DD/MM/YYYY HH24:MI:SS';
select server,service_name,sid,serial#,username,program,module,sql_id,logon_time,sql_exec_start,process
from v$session
where username='SCOTT'
order by server;


Options to take heapdump:
1) << this might not work for shared server case from another session
ORADEBUG SETMYPID or ORADEBUG SETORAPID <PID> or ORADEBUG SETOSPID <SPID>
ORADEBUG UNLIMIT
ALTER SESSION SET TRACEFILE_IDENTIFIER='PGA_UGA';
ORADEBUG DUMP HEAPDUMP 5
ORADEBUG CLOSE_TRACE

2)
alter session set events 'immediate trace name heapdump level 5';

There is also a mention about heapdump level 29,1025 for PGA. But let us examine level 5 for now.


Exercise:

A) Dedicated connection examination:


SQL> select server,service_name,sid,serial#,username,program,module,sql_id,prev_sql_id,logon_time,sql_exec_start,process
  2  from v$session
where username='SCOTT'
order by server;  3    4

SERVER     SERVICE_NAME        SID    SERIAL# USERNAME  PROGRAM                                       MODULE          SQL_ID          PREV_SQL_ID   LOGON_TIME         

SQL_EXEC_START      PROCESS
---------- ------------ ---------- ---------- --------- --------------------------------------------- --------------- ------------- ------------- -------------------

------------------- ------------------------
DEDICATED  oratest            261          5 SCOTT     sqlplus@host.oracle.com (TNS V1-V3)          SQL*Plus               6nar286qywyfa 10/03/2019 21:27:11           

          9538

SQL>

suppress the records for the query... by doing term off

sql_id = 6nar286qywyfa

so we have a shared sql area for this sql_id in shared pool.
Simillarly we have a cursor (pointer) for this sql_id in pga (UGA).
We will dump memory info now for this process.

select pid,spid,PGA_USED_MEM,PGA_ALLOC_MEM,PGA_FREEABLE_MEM,PGA_MAX_MEM
from v$process
where addr=(select paddr from v$session where sid=261);


SQL> select pid,spid,PGA_USED_MEM,PGA_ALLOC_MEM,PGA_FREEABLE_MEM,PGA_MAX_MEM
from v$process
where addr=(select paddr from v$session where sid=261);  2    3

       PID SPID                     PGA_USED_MEM PGA_ALLOC_MEM PGA_FREEABLE_MEM PGA_MAX_MEM
---------- ------------------------ ------------ ------------- ---------------- -----------
        49 9540                          1941437       3085525          1048576    14030037

===== actual session screen commands...

[oracle@host ~]$ sqlplus scott@oratest

SQL*Plus: Release 12.1.0.1.0 Production on Sun Mar 10 21:27:09 2019

...

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> @<labpath>/ugaexamination_lab.sql
SQL> alter session set events 'immediate trace name heapdump level 5';

Session altered.

SQL> exit


B) Shared server connection examination:

Note: restarted the db here to avoid cache & shared pool effect.

[oracle@host ~]$ tnsping oratest_shared

TNS Ping Utility for Linux: Version 12.1.0.1.0 - Production on 10-MAR-2019 21:31:40

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:
<ORACLE_HOME>/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = host)(PORT = 1521)) (CONNECT_DATA = (SERVER = SHARED) (SERVICE_NAME = oratest)))
OK (10 msec)


SQL> select server,service_name,sid,serial#,username,program,module,sql_id,logon_time,sql_exec_start,process
from v$session
where username='SCOTT'
order by server;  2    3    4

SERVER     SERVICE_NAME        SID    SERIAL# USERNAME  PROGRAM                                       MODULE          SQL_ID          LOGON_TIME         

SQL_EXEC_START      PROCESS
---------- ------------ ---------- ---------- --------- --------------------------------------------- --------------- ------------- -------------------

------------------- ------------------------
NONE       oratest             19          7 SCOTT     sqlplus@host.oracle.com (TNS V1-V3)          SQL*Plus               10/03/2019 21:32:09              9725

SQL>

SQL> select s.server,s.service_name,s.sid,s.serial#,s.username,s.sql_id,s.logon_time,s.sql_exec_start,s.process
from v$session s,v$circuit c
where c.saddr=s.saddr
order by server;  2    3    4

SERVER     SERVICE_NAME        SID    SERIAL# USERNAME  SQL_ID        LOGON_TIME          SQL_EXEC_START      PROCESS
---------- ------------ ---------- ---------- --------- ------------- ------------------- ------------------- ------------------------
NONE       oratest             19          7 SCOTT                   10/03/2019 21:32:09                     9725



SQL> select c.circuit,p1.pname disp_name, (case utl_raw.length(c.server) when 1 then 'NO_SERVER' else p2.pname end) ss_name,s.sid,s.serial#,c.status,c.queue
  2  from v$circuit c
  3  ,v$session s
  4  ,v$process p1
  5  ,v$process p2
where c.saddr=s.saddr
  6    7  and c.dispatcher=p1.addr
and c.server=p2.addr(+);
  8
CIRCUIT          DISP_ SS_NAME          SID    SERIAL# STATUS           QUEUE
---------------- ----- --------- ---------- ---------- ---------------- ----------------
0000000098434028 D000  NO_SERVER         19          7 NORMAL           NONE

SQL>

right now, there is no process this session is attached to, hence I am wondering how do we compute its pga, its not possibe since the shared server connection will move from one process to another (example dispatcher to shared server and to another shared server etc...), hence everytime we dump the information.. I think we will get only the pga of a dispatcher or shard server processes + UGA of the shared server connection. So this is going to work as per defination. Let us see...

select pid,spid,PGA_USED_MEM,PGA_ALLOC_MEM,PGA_FREEABLE_MEM,PGA_MAX_MEM
from v$process
where addr=(select paddr from v$session where sid=19);


SQL> select pid,spid,PGA_USED_MEM,PGA_ALLOC_MEM,PGA_FREEABLE_MEM,PGA_MAX_MEM
from v$process
where addr=(select paddr from v$session where sid=19);  2    3

       PID SPID                     PGA_USED_MEM PGA_ALLOC_MEM PGA_FREEABLE_MEM PGA_MAX_MEM
---------- ------------------------ ------------ ------------- ---------------- -----------
        21 9609                          1618357       1709269                0     1709269

SQL>
SQL> !ps -ef|grep 9609
oracle    9609     1  0 21:30 ?        00:00:00 ora_d000_oratest
oracle    9758  8856  0 21:36 pts/0    00:00:00 /bin/bash -c ps -ef|grep 9609
oracle    9760  9758  0 21:36 pts/0    00:00:00 grep 9609


<<<< right now the connection is idle, hence there wont be any process memory.


SQL> select server,service_name,sid,serial#,username,program,module,sql_id,prev_sql_id,logon_time,sql_exec_start,process
  2  from v$session
where username='SCOTT'
order by server;  3    4

SERVER     SERVICE_NAME        SID    SERIAL# USERNAME  PROGRAM                                       MODULE          SQL_ID          PREV_SQL_ID   LOGON_TIME         

SQL_EXEC_START      PROCESS
---------- ------------ ---------- ---------- --------- --------------------------------------------- --------------- ------------- ------------- -------------------

------------------- ------------------------
NONE       oratest             19          7 SCOTT     sqlplus@host.oracle.com (TNS V1-V3)          SQL*Plus               6nar286qywyfa 10/03/2019 21:32:09           

          9725

SQL>


so we executed the sql... it matches with the dedicated one. Let us go check its heapdump.. anyway see again the server is NONE now, so idle. Let us try it anyways. Being this is very spotaneous, i couldnt check which shared server took the process load of heapdump. But I saw in the trace dump directory s000 went ahead with update. So I belive the s000 is the one which took the process load. I also verified it by further probes below...

SQL> !ps -ef|grep ora_s|grep oratest
oracle    9599     1  0 21:30 ?        00:00:00 ora_smon_oratest
oracle    9615     1  0 21:30 ?        00:00:03 ora_s000_oratest    <<<<<<<<<< only one shared server which is s000
oracle    9633     1  0 21:30 ?        00:00:00 ora_smco_oratest
oracle    9855  8856  0 21:46 pts/0    00:00:00 /bin/bash -c ps -ef|grep ora_s|grep oratest

SQL> sho parameter shared

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
max_shared_servers                   integer
shared_servers                       integer     1

SQL> select * from V$SHARED_SERVER_MONITOR;

MAXIMUM_CONNECTIONS MAXIMUM_SESSIONS SERVERS_STARTED SERVERS_TERMINATED SERVERS_HIGHWATER     CON_ID
------------------- ---------------- --------------- ------------------ ----------------- ----------
                  1                1               0                  0                 1          0    <<< HWM is @ 1, so no new startups of shared server

SQL>

SQL> select pid,spid,PROGRAM,pname,BACKGROUND,PGA_USED_MEM,PGA_ALLOC_MEM,PGA_FREEABLE_MEM,PGA_MAX_MEM from v$process where pname like 'S%';

       PID SPID                     PROGRAM                                       PNAME B PGA_USED_MEM PGA_ALLOC_MEM PGA_FREEABLE_MEM PGA_MAX_MEM
---------- ------------------------ --------------------------------------------- ----- - ------------ ------------- ---------------- -----------
        16 9599                     oracle@host.oracle.com (SMON)                SMON  1      1361061       1774805     65536      1774805
        24 9615                     oracle@host.oracle.com (S000)                S000         1025213       2216501           983040      10408501
        28 9633                     oracle@host.oracle.com (SMCO)                SMCO  1      1128053       1250517         0      1250517

SQL>



drwxr-x---.  6 oracle oracle   131072 Mar 10 21:44 .
-rw-r-----.  1 oracle oracle      403 Mar 10 21:44 oratest_s000_9615.trm
-rw-r-----.  1 oracle oracle    87919 Mar 10 21:44 oratest_s000_9615.trc
[oracle@host trace]$ date
Sun Mar 10 21:45:59 CST 2019
[oracle@host trace]$

==ACTUAL SCREEN of shared server connection:

[oracle@host ~]$ sqlplus scott@oratest_shared

...

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> @<labpath>/ugaexamination_lab.sql
SQL> alter session set events 'immediate trace name heapdump level 5';

Session altered.

SQL> exit

######### Analyze the difference

so we are good to examine the difference... what we will learn here is, the s000 was idle before, it did only one processing which is the sql as dedicated. Hence its pga is valid to be considered.

[oracle@host lab10mar19]$ ls -altr *PGAHEAP
-rw-r-----. 1 oracle oracle 87919 Mar 10 21:54 oratest_s000_9615.trc_SHARED_PGAHEAP
-rw-r-----. 1 oracle oracle 81928 Mar 10 21:54 oratest_ora_9540.trc_DEDICATED_PGAHEAP
[oracle@host lab10mar19]$

for an idle shared server.. the memory usage is...

SQL> select pid,spid,PROGRAM,pname,BACKGROUND,PGA_USED_MEM,PGA_ALLOC_MEM,PGA_FREEABLE_MEM,PGA_MAX_MEM from v$process where pname like 'S000%';

       PID SPID                     PROGRAM                                          PNAME B PGA_USED_MEM PGA_ALLOC_MEM PGA_FREEABLE_MEM PGA_MAX_MEM
---------- ------------------------ ------------------------------------------------ ----- - ------------ ------------- ---------------- -----------
        24 10690                    oracle@host.oracle.com (S000)                   S000          930629       1053909         0     1053909

SQL>


post processing a session... [dont worry abt spid change, i did bounce the db to reverify this figures].


SQL> select pid,spid,PROGRAM,pname,BACKGROUND,PGA_USED_MEM,PGA_ALLOC_MEM,PGA_FREEABLE_MEM,PGA_MAX_MEM from v$process where pname like 'S%';

       PID SPID                     PROGRAM                                       PNAME B PGA_USED_MEM PGA_ALLOC_MEM PGA_FREEABLE_MEM PGA_MAX_MEM
---------- ------------------------ --------------------------------------------- ----- - ------------ ------------- ---------------- -----------
        24 9615                     oracle@host.oracle.com (S000)                S000         1025213       2216501           983040      10408501



for 10690 spid - the verification one:

       PID SPID                     PROGRAM                                          PNAME B PGA_USED_MEM PGA_ALLOC_MEM PGA_FREEABLE_MEM PGA_MAX_MEM
---------- ------------------------ ------------------------------------------------ ----- - ------------ ------------- ---------------- -----------
        24 10690                    oracle@host.oracle.com (S000)                   S000         1025213       2216501    983040    10408501



#### Let us use heap dump analyzer (credits to Tanel Poder, https://blog.tanelpoder.com/2009/01/02/oracle-memory-troubleshooting-part-1-heapdump-analyzer/)

I applied the heap dump analyzer to see a summary of heap distribution and observed the below....

dedicated:

chunk_Type_analyticalFrom_heapSUM of Total_sizeSUM of #Chunks
freeablepga heap33129669

session heap604704607

top call heap380329

top uga heap78614412
freeable Total
1760176697
non_freepga heap67498448

session heap24632091

top call heap274806

top uga heap655122
non_free Total
1014296147
Grand Total
2774472844


shared: 

chunk_type_analyticsFrom_heapSUM of Total_sizeSUM of #Chunks
freeablepga heap25875266

session heap751776664

top call heap380329
freeable Total
1048560739
non_freeablepga heap73047251

session heap279360116

top call heap929928
non_freeable Total

1102824175
Grand Total
2151384914


The dedicated pga size does differ  from heapdump trace value vs shared server heap dump is matching close (in its usage as well).

Learning: On dedicated connection heapdump we see uga heaps vs on the shared server connection we dont see the uga heap. This is in line with oracle documentation. The uga should have been allocated from the oracle sga, may be in next exercise we will see which memory area is hosting this uga (shared pool or large pool).

Thanks for paying a visit, your feedback is welcome.
















































Flashback data archive steps

 Objective: Ways to track DML changes in a table Detailed objective: We should be able to track the changes in the table at any point in tim...