HPUX sleep effect on CPU time slize and thread priority - HP UX

This is a discussion on HPUX sleep effect on CPU time slize and thread priority - HP UX ; I have several client application that do same processing. The application is spawn by another application called server. One of them is recently patched to sleep just between being fork and spawn. So the way it is done is in ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: HPUX sleep effect on CPU time slize and thread priority

  1. HPUX sleep effect on CPU time slize and thread priority

    I have several client application that do same processing. The
    application is spawn by another application called server. One of them
    is recently patched to sleep just between being fork and spawn.

    So the way it is done is in server application, fork to client thread
    and server thread.

    ----------------------------

    //server code
    pid_t pId = fork();

    //Lots of code

    if (pId == 0)
    {
    //The way I understood it, this is the client thread

    usleep(500000L); //Sleep 500 milisecond

    //Lots of code

    execv(client, param);
    }
    else if (pId < 0)
    {
    //Some error message
    }
    else
    {
    //The way I understood it, this is the parent thread
    //Add some come to keep thread the client
    }

    ----------------------------

    My question:

    It seems that after this change, the particular client utilizing less
    CPU compared to other client without this change. Even though they
    have the same nice level (which is 22). However I cannot understand
    this behavior.

    When other client is not processing, let say during midnight. My
    client will perform well. Which is measured by how much file it can
    process per hour.

    But during peak hours, my client will process significantly less
    amount of file compared to its highest value at midnight.

    So

    1. I'm trying to understand how usleep() can cause this.

    2. I'm wondering about trying to adjust my client nice value to -2
    (which is 20) compared to other client (which is 22).

    Appreciate any feedback. I am a developer first, beginners in unix and
    find all of this as very fascinating.

    Best Regards

  2. Re: HPUX sleep effect on CPU time slize and thread priority

    xbokZero@gmail.com wrote:
    > I have several client application that do same processing. The
    > application is spawn by another application called server. One of
    > them is recently patched to sleep just between being fork and spawn.


    > So the way it is done is in server application, fork to client
    > thread and server thread.


    A wording nit - fork() creats a child _process_ not a thread - calling
    it a thread implies (at least to some) something like POSIX threads.


    > ----------------------------


    > //server code
    > pid_t pId = fork();


    > //Lots of code


    > if (pId == 0)
    > {
    > //The way I understood it, this is the client thread


    > usleep(500000L); //Sleep 500 milisecond


    Out of curiousity, why the sleep?

    rick jones
    --
    denial, anger, bargaining, depression, acceptance, rebirth...
    where do you want to be today?
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

  3. Re: HPUX sleep effect on CPU time slize and thread priority

    On Nov 17, 5:28 am, Rick Jones wrote:
    > xbokZ...@gmail.com wrote:
    > > I have several client application that do same processing. The
    > > application is spawn by another application called server. One of
    > > them is recently patched tosleepjust between being fork and spawn.
    > > So the way it is done is in server application, fork to client
    > >threadand serverthread.

    >
    > A wording nit - fork() creats a child _process_ not athread- calling
    > it athreadimplies (at least to some) something like POSIX threads.
    >
    > > ----------------------------
    > > //server code
    > > pid_t pId = fork();
    > > //Lots of code
    > > if (pId == 0)
    > > {
    > > //The way I understood it, this is the clientthread
    > > usleep(500000L); //Sleep500 milisecond

    >
    > Out of curiousity, why thesleep?
    >
    > rick jones
    > --
    > denial, anger, bargaining, depression, acceptance, rebirth...
    > where do you want to be today?
    > these opinions are mine, all mine; HP might not want them anyway...
    > feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...


    OK my bad! I really thought client process equal to a new thread.

    The sleep function is to delay it a few hundred millisecond so that
    some code in the else (parent process) part is executed first. I guess
    that hold true if child process is something like a thread.

    I got a feeling that I'm not understanding how fork work by assuming
    that it create another thread. Please advise me on this.

    I'm still curios on the answer to first post question.

    Best regards!


  4. Re: HPUX sleep effect on CPU time slize and thread priority

    xbokZero@gmail.com wrote:
    > The sleep function is to delay it a few hundred millisecond so that
    > some code in the else (parent process) part is executed first. I
    > guess that hold true if child process is something like a thread.


    Sleep is a very, Very, VERY poor synchronization mechanism. If it is
    the case that some stuff in the parent must execute first then you
    should setup some sort of more explicit indication that the work has
    taken place.

    > I got a feeling that I'm not understanding how fork work by assuming
    > that it create another thread. Please advise me on this.


    A "thread" is generally a (sigh) "thread of execution," sharing
    address space with other threads of execution in the same process.

    The fork() call makes a new process. The new process will have its own
    address space. It will have within it a single thread.

    A new thread in the same process is created with pthread_create().

    So, strictly speaking I suppose that fork() will create a new "thread"
    but in a new process. That is why generally one talks about fork()
    creating a new process, not a new thread. Saying one is creating a
    new thread implies a pthread_create() call.

    > I'm still curios on the answer to first post question.


    I am afraid I don't have an answer to that one. You might try taking
    system call traces to see that the two processes are indeed making the
    same sorts of calls.

    rick jones
    --
    The computing industry isn't as much a game of "Follow The Leader" as
    it is one of "Ring Around the Rosy" or perhaps "Duck Duck Goose."
    - Rick Jones
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

+ Reply to Thread