Unix Technical Forum

HPUX sleep effect on CPU time slize and thread priority

This is a discussion on HPUX sleep effect on CPU time slize and thread priority within the HP-UX Operating System forums, part of the Unix Operating Systems category; --> I have several client application that do same processing. The application is spawn by another application called server. One ...


Go Back   Unix Technical Forum > Unix Operating Systems > HP-UX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-17-2008, 06:02 AM
xbokZero@gmail.com
 
Posts: n/a
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-17-2008, 06:02 AM
Rick Jones
 
Posts: n/a
Default 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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-17-2008, 06:02 AM
xbokZero@gmail.com
 
Posts: n/a
Default Re: HPUX sleep effect on CPU time slize and thread priority

On Nov 17, 5:28 am, Rick Jones <rick.jon...@hp.com> 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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-17-2008, 06:03 AM
Rick Jones
 
Posts: n/a
Default 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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:10 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com