Informix

 View Only
  • 1.  How to wait milliseconds within SPL?

    Posted Thu December 02, 2021 11:42 PM
    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
    ------------------------------


  • 2.  RE: How to wait milliseconds within SPL?

    Posted Tue December 14, 2021 03:46 PM


    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
    ------------------------------



  • 3.  RE: How to wait milliseconds within SPL?

    InnerCircle
    Posted Tue December 14, 2021 04:29 PM
    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
    ------------------------------



  • 4.  RE: How to wait milliseconds within SPL?

    IBM Champion
    Posted Tue December 14, 2021 05:14 PM
    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
    ------------------------------



  • 5.  RE: How to wait milliseconds within SPL?

    Posted Tue December 14, 2021 05:27 PM

    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

     

     






  • 6.  RE: How to wait milliseconds within SPL?

    Posted Tue December 14, 2021 05:40 PM

    Been playing on my Linux, usleep (1) maps to nanosleep(0,1000) – live and learn

     






  • 7.  RE: How to wait milliseconds within SPL?

    Posted Tue December 14, 2021 06:47 PM

    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();

        }

    }

     

     






  • 8.  RE: How to wait milliseconds within SPL?

    Posted Tue December 14, 2021 04:59 PM

    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