How to wait milliseconds within SPL?
Answered: amber (hollow confidence) — Consensus is a C UDR with short OS sleeps combined with mi_yield; Paul Watson posted a working clock_nanosleep/mi_yield sample on Linux, though the asker (on AIX) never confirmed.
Advisory only.
Posted in 2021
SangGyu Jeong asked how to sleep for milliseconds in SPL on AIX, where system sleep and yieldn did not work. David Williams suggested a C UDR; Andreas Legner and Paul Watson warned it must yield (mi_yield) or the CPU VP is lost to the OS. Art Kagel offered a gettimeofday UDR; Paul posted a clock_nanosleep loop with mi_yield that worked on Linux.
Topics: Stored Procedures & SPL, Platform-Specific Issues
Hello All,
Is there a function in SPL that works similar to sleep?
I used system ('sleep 5') , sysmaster:yieldn(), sysadmin:yieldn() functions, etc, but it doesn't seem to work in milisecond units. Because it is an AIX environment, usleep or nsleep cannot be used.
Any ideas?
drop procedure myproc;
create procedure myproc()
insert into tmp1 select dbinfo('utc_to_datetime',sh_curtime) from sysmaster:sysshmvals;select sysmaster:yieldn(0.01) y from sysmaster:sysdual into temp ifxtmp1 with no log;
insert into tmp1 select dbinfo('utc_to_datetime',sh_curtime) from sysmaster:sysshmvals;
drop table ifxtmp1;end procedure;
------------------------------
SangGyu Jeong
Software Engineer
Infrasoft
Seoul Korea, Republic of
------------------------------
#Informix
Hi, Write a C UDR which calls whatever OS function can do sub-second sleeps. A C UDR can be written something similar to (if you use gcc): https://justdaveinfo.wordpress.com/2015/04/26/simple-informix-c-udr-on-centos-6-6/ Regards, David. ------------------------------ David Williams ------------------------------
Problem with this probably would be that, instead of yielding the Informix thread (to another one) while 'sleeping', you'd yield the cpu vp (to the OS). ------------------------------ Andreas Legner ------------------------------
Don't do that – your engine will not love you for it. You need to do very small micro sleeps with lots of mi_yield otherwise you will probably lose the VP you are running in to the OS Cheers Paul
I have a UDR that calls gettimeofday() to return microsecond resolution time. One could loop on that call until the desired sub-second time had elapsed.
> execute function adbm_gettimeofday();(expression)
2021-12-14 17:00:21.93423
1 row(s) retrieved.
If anyone is interested in the source, email me.
------------------------------
Art S. Kagel, President and Principal Consultant
ASK Database Management Corp.
www.askdbmgt.com
------------------------------
The high level logic in the UDR is for(i=HowLongMS; i--;) { usleep(1) Mi_yield() } You don't want to directly sleep for 25ms, the engine can do a lot in 25ms J You could look at nanosleep but I suspect that is not what you want. Cheers Paul
Been playing on my Linux, usleep (1) maps to nanosleep(0,1000) – live and learn
Appears to work under Linux void oni_sleep(mi_integer ms) { struct timespec ts; int i; long next_tick; clock_getres(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts); for(i=ms;i--;) { next_tick = (ts.tv_sec * 1000000000L + ts.tv_nsec) + 1000000; ts.tv_sec = next_tick / 1000000000L; ts.tv_nsec = next_tick % 1000000000L; clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL); mi_yield(); } }