Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Thread Creation Overhead vs Synchronization overhead

807557Nov 10 2009
Hello,

I need to know the relative overheads of a new thread creation every time a new request is serviced vs having a dedicated thread waiting for a request, which gets woken using the pthread_cond_signal / pthread_cond_wait calls.
Note:
- The applicaiton is a server.
- The thread in question is a light-weight thread used only for implementing timeout.
- The main thread is the one which executes the core logic

The timeout is implemented in this way:
- on a new request, the main thread spawns a new threads which waits for a specificed number of seconds[ sleep or an equivalent ] , say x, which is the application timeout. If sleep is not interrupted, and x seconds have elapesed, sets a global denoting that timeout has happened.
- The main thread [ core logic ] checks for this state at safe points, if timeout is detected, aborts the logic and gracefully exits after terminating the timer threads[ pthread_cancel].

The questions that I have are:
- As every request creates a new thread, what is the overhead ?

The alternative option is to have one long running thread, that wakes up on a new request [ main thread does pthread_cond_signal ] and the long running threds blocks on a wait.

I want to know which of them is a better option ? I read in one of the posts that for a rpc kind of applicaiton, one thread per request may be better. Any Comments ?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 8 2009
Added on Nov 10 2009
0 comments
85 views