none
Thread pool and Processor Utilization? RRS feed

  • Question


  • I've already implemented thread pool in my server. Before to that, I was managing threads with my own thread management mechanism. But after the implementation I found the thread pool (in my Windows service) is utilizing my processor 50% constantly. There are other applications/services running in my server. I feel these are getting affected due to this Confused.

    Can you give me a suggestion regarding this issue?


    Ganesh Kumar
    Friday, January 9, 2009 1:50 AM

Answers

  •  Without seeing any snippets of code my current guess is that the threads that scans for files don't have a small sleep in them and executes over and over and over clogging up the cpu resources. but then again without more info its just a guess.  As always if you want to know where cpu time is being spend run your code through a profiler like antz
    • Marked as answer by Zhi-Xin Ye Thursday, January 15, 2009 7:16 AM
    • Marked as answer by Zhi-Xin Ye Thursday, January 15, 2009 7:34 AM
    Friday, January 9, 2009 3:51 PM

All replies

  • Your thread(s) are running full-bore, never getting blocked by anything like I/O or waiting on a lock.  That's usually a Good Thing, real work is getting done.   Or a Bad Thing, if they are just busy but not accomplishing anything.  I can't tell from your post.
    Hans Passant.
    Friday, January 9, 2009 1:59 AM
    Moderator
  • Let me explain the scenario.

    My Windows service is having following threads to be managed by thread pool,

    1. Thread to pick files as soon as it reaches a watch folder and moving it to the other folder for processing.

    2. A Thread to open the text file and read information in that and interpret them in to a datatable ( For each file I am creating a thread). There are different type of files come to my watch folder and each format will be interpreted by different version of threads into a common-structured datatable.

    3. A thread to validate and populate the information in data table into database using bulkcopy object. (the 3rd thread is created by the 2nd thread at the end of its process.)

    I am keeping Maximum of 10 threads in the pool. Some time around 10 to 20 files come the watch folder per 1 minute. Some other time there may not be even a single file...

    I hope you understand the nature of business the processes do...

    Ganesh Kumar
    Friday, January 9, 2009 6:36 AM
  • Well, it tells me squat about the code that you wrote, only snippets can fix that.  But yes, those threads shouldn't be very busy at all.  Using more than one thread doesn't make sense, your code is completely I/O bound by the (very slow) disk.
    Hans Passant.
    Friday, January 9, 2009 10:52 AM
    Moderator
  •  Without seeing any snippets of code my current guess is that the threads that scans for files don't have a small sleep in them and executes over and over and over clogging up the cpu resources. but then again without more info its just a guess.  As always if you want to know where cpu time is being spend run your code through a profiler like antz
    • Marked as answer by Zhi-Xin Ye Thursday, January 15, 2009 7:16 AM
    • Marked as answer by Zhi-Xin Ye Thursday, January 15, 2009 7:34 AM
    Friday, January 9, 2009 3:51 PM