Discussion:
nmon and Top Processes
(too old to reply)
t***@gmail.com
2013-03-19 18:27:47 UTC
Permalink
When watching the top processes in nmon and what is driving oninit for work, PID's are shown next to the %cpu used.

how can i relate those PID's back to sessions id's within the instance?

thanks,
tom
Jonathan Leffler
2013-03-19 18:38:14 UTC
Permalink
Post by t***@gmail.com
When watching the top processes in nmon and what is driving oninit for
work, PID's are shown next to the %cpu used.
How can I relate those PID's back to sessions id's within the instance?
Are you asking for client PIDs or server PIDs?

For client PIDs, you can look at the PID column in 'onstat -g ses' output.
However, JDBC processes don't send the relevant information to the server,
and remote processes report the PID on their machine.

For server PIDs, you can't. A single session may run at different times on
many different processes within a server. A single process will serve many
sessions over its lifetime. There is no 1:1 relationship between PIDs of
the server and the client.
--
Jonathan Leffler <***@gmail.com> #include <disclaimer.h>
Guardian of DBD::Informix - v2013.0118 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."
Cesar Inacio Martins
2013-03-19 20:08:15 UTC
Permalink
I use the cpu_time statistics to detect who is "eating" my CPUs....

This is the copy of the base SQLs from script I wrote .

The logic is simple... save each N seconds a "snapshot" of all sessions
statistics and show the difference between last two snapshot, sorting by
who have bigger consumption.

Maybe need adjust for you need...

-- first create this table...
create raw table mon_users_cpu_cesar (
id int
,usuario char(18)
,sesid int
,pid int
,cpu_time float
,last_run datetime year to second
,hora datetime year to second

,tx_nlocks integer { number of locks currently held}
,tx_logspuse integer { % log space currently used }
,tx_lgrecs integer { numbe of log records written }

,io_seqscans integer { number of sequential scans }
,io_waittime float { time spent waiting on disk io }
,io_nwaits integer { Number of disk IO waits }
,io_idxbufr integer { Number of index buffer reads }
,io_bufreads integer { ... buffer reads }
,io_bufwrites integer { ... buffer writes }
,io_nreads integer { number of reads (paginas) }
,io_nwrites integer { number of writes (paginas) }

,is_read integer { number of reads request }
,is_write integer { number of writes request }
,is_rwrite integer { number of rewrites request }
,is_delete integer { number of deletes request }
,is_commit integer { number of commits request }
,is_rollback integer { number of rollbacks request }

)
;
create index ix1_mon_users_cpu_cesar on mon_users_cpu_cesar (id, sesid,
usuario );

-- then, execute this commands each N seconds...

select max(nvl(id,0))+1 as next_seq
from mon_users_cpu_cesar
into temp tp_mon_cesar
with no log ;

insert into mon_users_cpu_cesar
select tp.next_seq
, s.username
, s.sid
, s.pid
, sum(t.cpu_time) as cpu_time
, max(dbinfo('utc_to_datetime', t.last_run_time)) as last_run
, current hour to second as hora

, sum(u.nlocks)
, sum(u.upf_logspuse)
, sum(u.upf_lgrecs)

, sum(u.upf_seqscans)
, sum(u.iowaittime)
, sum(u.upf_niowaits)
, sum(u.upf_idxbufreads)
, sum(u.upf_bufreads)
, sum(u.upf_bufwrites)
, sum(u.nreads)
, sum(u.nwrites)

, sum(u.upf_isread)
, sum(u.upf_iswrite)
, sum(u.upf_isrwrite)
, sum(u.upf_isdelete)
, sum(u.upf_iscommit)
, sum(u.upf_isrollback)
from sysmaster:syssessions s
, sysmaster:sysrstcb u --sysmaster:sysuserthreads u
, sysmaster:systcblst t
, tp_mon_cesar tp
where u.sid = s.sid
and u.tid = t.tid
group by 1
, 2
, 3
, 4
;

-- show the top 10 sessions with more CPU use on the last N seconds...

select first 10
m1.sesid
, m1.usuario
, (nvl(m1.cpu_time,0) - nvl(m2.cpu_time,0))::dec(15,2) as cpu_time1
-- , m1.last_run
, (m1.hora - m2.hora)::interval day to second as __tempo_exec
, (current -m1.last_run)::interval day to second as __tempo_idle
-- , m1.*
-- , m2.*
from mon_users_cpu_cesar m1
, outer (mon_users_cpu_cesar m2)
, tp_mon_cesar tp
where m1.id = tp.next_seq
and m2.id = (m1.id-1)
and m2.sesid = m1.sesid
and m2.usuario = m1.usuario
order by cpu_time1 desc
;
Post by t***@gmail.com
When watching the top processes in nmon and what is driving oninit for
work, PID's are shown next to the %cpu used.
how can i relate those PID's back to sessions id's within the instance?
thanks,
tom
_______________________________________________
Informix-list mailing list
http://www.iiug.org/mailman/listinfo/informix-list
Cesar Inacio Martins
2013-03-19 20:22:34 UTC
Permalink
I forgot...
include this delete at the end of the script .. or the table will grown
unnecessary.

delete from mon_users_cpu_cesar where id < (select next_seq - 50 from
tp_mon_cesar) ;
Post by Cesar Inacio Martins
I use the cpu_time statistics to detect who is "eating" my CPUs....
This is the copy of the base SQLs from script I wrote .
The logic is simple... save each N seconds a "snapshot" of all sessions
statistics and show the difference between last two snapshot, sorting by
who have bigger consumption.
Maybe need adjust for you need...
-- first create this table...
create raw table mon_users_cpu_cesar (
id int
,usuario char(18)
,sesid int
,pid int
,cpu_time float
,last_run datetime year to second
,hora datetime year to second
,tx_nlocks integer { number of locks currently held}
,tx_logspuse integer { % log space currently used }
,tx_lgrecs integer { numbe of log records written }
,io_seqscans integer { number of sequential scans }
,io_waittime float { time spent waiting on disk io }
,io_nwaits integer { Number of disk IO waits }
,io_idxbufr integer { Number of index buffer reads }
,io_bufreads integer { ... buffer reads }
,io_bufwrites integer { ... buffer writes }
,io_nreads integer { number of reads (paginas) }
,io_nwrites integer { number of writes (paginas) }
,is_read integer { number of reads request }
,is_write integer { number of writes request }
,is_rwrite integer { number of rewrites request }
,is_delete integer { number of deletes request }
,is_commit integer { number of commits request }
,is_rollback integer { number of rollbacks request }
)
;
create index ix1_mon_users_cpu_cesar on mon_users_cpu_cesar (id, sesid,
usuario );
-- then, execute this commands each N seconds...
select max(nvl(id,0))+1 as next_seq
from mon_users_cpu_cesar
into temp tp_mon_cesar
with no log ;
insert into mon_users_cpu_cesar
select tp.next_seq
, s.username
, s.sid
, s.pid
, sum(t.cpu_time) as cpu_time
, max(dbinfo('utc_to_datetime', t.last_run_time)) as last_run
, current hour to second as hora
, sum(u.nlocks)
, sum(u.upf_logspuse)
, sum(u.upf_lgrecs)
, sum(u.upf_seqscans)
, sum(u.iowaittime)
, sum(u.upf_niowaits)
, sum(u.upf_idxbufreads)
, sum(u.upf_bufreads)
, sum(u.upf_bufwrites)
, sum(u.nreads)
, sum(u.nwrites)
, sum(u.upf_isread)
, sum(u.upf_iswrite)
, sum(u.upf_isrwrite)
, sum(u.upf_isdelete)
, sum(u.upf_iscommit)
, sum(u.upf_isrollback)
from sysmaster:syssessions s
, sysmaster:sysrstcb u --sysmaster:sysuserthreads u
, sysmaster:systcblst t
, tp_mon_cesar tp
where u.sid = s.sid
and u.tid = t.tid
group by 1
, 2
, 3
, 4
;
-- show the top 10 sessions with more CPU use on the last N seconds...
select first 10
m1.sesid
, m1.usuario
, (nvl(m1.cpu_time,0) - nvl(m2.cpu_time,0))::dec(15,2) as cpu_time1
-- , m1.last_run
, (m1.hora - m2.hora)::interval day to second as __tempo_exec
, (current -m1.last_run)::interval day to second as __tempo_idle
-- , m1.*
-- , m2.*
from mon_users_cpu_cesar m1
, outer (mon_users_cpu_cesar m2)
, tp_mon_cesar tp
where m1.id = tp.next_seq
and m2.id = (m1.id-1)
and m2.sesid = m1.sesid
and m2.usuario = m1.usuario
order by cpu_time1 desc
;
Post by t***@gmail.com
When watching the top processes in nmon and what is driving oninit for
work, PID's are shown next to the %cpu used.
how can i relate those PID's back to sessions id's within the instance?
thanks,
tom
_______________________________________________
Informix-list mailing list
http://www.iiug.org/mailman/listinfo/informix-list
Fernando Nunes
2013-03-19 22:00:31 UTC
Permalink
Hello Tom,

As Jonathan wrote, Informix doesn't have a 1:1 PID vs session relation (at
least Informix Dynamic Server), but I suppose you already know that.
In order to quickly find the sessions consuming more CPU at a specific time
you can use a script that interacts through several "onstat -g act" and
counts the number of times the sessions are caught running.
The is a script on the IIUG repository called *top* that allows you to do
that on a very rudimentary way. Some years agor I picked that script and
tried to enhance it.
You can find the result (and several others, but unfortunately
undocumented) here:

http://onlinedomus.com/informix/viewvc.cgi/PUBLIC/informix/scripts/ix/

(look for ixtop).

If you run "ixtop -h" it will provide a brief help. The most important
options are "-n" and "-c":
-n N will run onstat -g act N times
-c C means only sessions that were caught C times within the N runs are
displayed

One of the original problems in the original script is that onstat -g act
would take a long time to run (specially on systems with audit turned on).
The solution was o run an "onstat -i" and echo "g act" to it. Much faster,
meaning the measure is much more meaningful and we can run it many times
(the default IIRC is 50 or 100 times)
Be carefull with the following: The version on that page has a bug that if
you interrupt it it will probably leave "onstat -i" running and consuming
lots of CPU! I already have the fix but haven't "published" it yet.

Other important options are:
-t T that will show you only the T top most sessions
-e "ses" (other options are available, but depnd on other scripts). This
will immediately run "onstat -g ses" for the sessions it founds. This is
important, because many times if you wait to get the session numbers and
then try to get their info, what you'll see are not the problematic queries
but the ones that follow them (or you may catch the session already idle).

ixtop will also show you the top "tables" (given a criteria like seq scans,
bufreads, bufwrites etc...)
It can also show similar info, but for sessions. But here consider that
it's the absolute values (not the latest N seconds for example). For that I
believe that what Cesar posted may be more helpful. The problem in showing
absolute values is that long standing sessions like the ones from
application servers tend to be on top, just because they are older.

Regards.
Post by t***@gmail.com
When watching the top processes in nmon and what is driving oninit for
work, PID's are shown next to the %cpu used.
how can i relate those PID's back to sessions id's within the instance?
thanks,
tom
_______________________________________________
Informix-list mailing list
http://www.iiug.org/mailman/listinfo/informix-list
--
Fernando Nunes
Portugal

http://informix-technology.blogspot.com
My email works... but I don't check it frequently...
Fernando Nunes
2013-03-19 22:02:35 UTC
Permalink
Important note: Use any of this scripts at your own risk. Most of them have
been in use in some customers successfully for some time (years) but that
doesn't mean they don't contain bugs. For sure, there are bugs.
Regards
Post by Fernando Nunes
Hello Tom,
As Jonathan wrote, Informix doesn't have a 1:1 PID vs session relation (at
least Informix Dynamic Server), but I suppose you already know that.
In order to quickly find the sessions consuming more CPU at a specific
time you can use a script that interacts through several "onstat -g act"
and counts the number of times the sessions are caught running.
The is a script on the IIUG repository called *top* that allows you to do
that on a very rudimentary way. Some years agor I picked that script and
tried to enhance it.
You can find the result (and several others, but unfortunately
http://onlinedomus.com/informix/viewvc.cgi/PUBLIC/informix/scripts/ix/
(look for ixtop).
If you run "ixtop -h" it will provide a brief help. The most important
-n N will run onstat -g act N times
-c C means only sessions that were caught C times within the N runs are
displayed
One of the original problems in the original script is that onstat -g act
would take a long time to run (specially on systems with audit turned on).
The solution was o run an "onstat -i" and echo "g act" to it. Much faster,
meaning the measure is much more meaningful and we can run it many times
(the default IIRC is 50 or 100 times)
Be carefull with the following: The version on that page has a bug that if
you interrupt it it will probably leave "onstat -i" running and consuming
lots of CPU! I already have the fix but haven't "published" it yet.
-t T that will show you only the T top most sessions
-e "ses" (other options are available, but depnd on other scripts). This
will immediately run "onstat -g ses" for the sessions it founds. This is
important, because many times if you wait to get the session numbers and
then try to get their info, what you'll see are not the problematic queries
but the ones that follow them (or you may catch the session already idle).
ixtop will also show you the top "tables" (given a criteria like seq
scans, bufreads, bufwrites etc...)
It can also show similar info, but for sessions. But here consider that
it's the absolute values (not the latest N seconds for example). For that I
believe that what Cesar posted may be more helpful. The problem in showing
absolute values is that long standing sessions like the ones from
application servers tend to be on top, just because they are older.
Regards.
Post by t***@gmail.com
When watching the top processes in nmon and what is driving oninit for
work, PID's are shown next to the %cpu used.
how can i relate those PID's back to sessions id's within the instance?
thanks,
tom
_______________________________________________
Informix-list mailing list
http://www.iiug.org/mailman/listinfo/informix-list
--
Fernando Nunes
Portugal
http://informix-technology.blogspot.com
My email works... but I don't check it frequently...
--
Fernando Nunes
Portugal

http://informix-technology.blogspot.com
My email works... but I don't check it frequently...
t***@gmail.com
2013-03-22 14:17:28 UTC
Permalink
Many Thanks to all!
Tom

Loading...