J
JMZ
I have a .Net service that processes messages contained in disk files using 1
or more threads. We run this on a server with 4 CPUs. We allow it to have up
to 8 active threads processing messages from a synchronized blocking queue.
The threads are long-running custom threadpool threads. Each thread can be in
one of several states - running, suspended, stopping, stopped. These are
logical states and not the states associated with the actual ThreadState
property of the thread. We use AutoResetEvents to manage them.
The service is scheduled using an Alarm component that reads its schedule
from the database. In each logical schedule, the number of threads and the
next schedule start are assigned. The Alarm is set to the next schedule start
time and raises an event which is handled by the method that reads the
schedule from the database. Each time this method runs, it sets the number of
running threads, along with some other associated data, and sets the next
Alarm.
Each thread is created at startup of the service, and contains many object
instances, including datasets and dataviews of static data.
The main dispatching thread is responsible for looking for the message
files, enqueuing them, and pausing whenever the number of threads is set to
zero. We use zero during times we want processing to stop for a specified
period, such as when we run nightly ETL. These periods are also part of the
schedule in the database. The schedule consists of all the periods we want to
change processing parameters for a week. Each week, the schedule repeats.
During off hours, we take advantage by scheduling more threads. During
business hours, we schedule fewer threads to reduce the performance impact to
an associated web application that shares its database.
We have done significant performance testing to ensure this methodology does
in fact produce the best performance. The .Net ThreadPool, in our testing,
did not perform well. Also, creating a new thread for each new message is
extremely slow because of the large number of objects it must create. The
custom threadpool perfoms very well at 1 to 2 seconds per message.
Occaisionally, the service terminates unexpectedly with no event log entries
or any other events that could be associated to it. Sometimes it stops during
a schedule change. Most of the time, we end up with one or more messages in
an inconsistent state, which we have to then recover.
My questions are as follows:
1. With a custom threadpool, should I be recycling the threads at some
interval, creating all new objects and datasets, etc?
2. Are there any other factors I should be considering that I have not
touched on above?
Thank you very much for any help.
or more threads. We run this on a server with 4 CPUs. We allow it to have up
to 8 active threads processing messages from a synchronized blocking queue.
The threads are long-running custom threadpool threads. Each thread can be in
one of several states - running, suspended, stopping, stopped. These are
logical states and not the states associated with the actual ThreadState
property of the thread. We use AutoResetEvents to manage them.
The service is scheduled using an Alarm component that reads its schedule
from the database. In each logical schedule, the number of threads and the
next schedule start are assigned. The Alarm is set to the next schedule start
time and raises an event which is handled by the method that reads the
schedule from the database. Each time this method runs, it sets the number of
running threads, along with some other associated data, and sets the next
Alarm.
Each thread is created at startup of the service, and contains many object
instances, including datasets and dataviews of static data.
The main dispatching thread is responsible for looking for the message
files, enqueuing them, and pausing whenever the number of threads is set to
zero. We use zero during times we want processing to stop for a specified
period, such as when we run nightly ETL. These periods are also part of the
schedule in the database. The schedule consists of all the periods we want to
change processing parameters for a week. Each week, the schedule repeats.
During off hours, we take advantage by scheduling more threads. During
business hours, we schedule fewer threads to reduce the performance impact to
an associated web application that shares its database.
We have done significant performance testing to ensure this methodology does
in fact produce the best performance. The .Net ThreadPool, in our testing,
did not perform well. Also, creating a new thread for each new message is
extremely slow because of the large number of objects it must create. The
custom threadpool perfoms very well at 1 to 2 seconds per message.
Occaisionally, the service terminates unexpectedly with no event log entries
or any other events that could be associated to it. Sometimes it stops during
a schedule change. Most of the time, we end up with one or more messages in
an inconsistent state, which we have to then recover.
My questions are as follows:
1. With a custom threadpool, should I be recycling the threads at some
interval, creating all new objects and datasets, etc?
2. Are there any other factors I should be considering that I have not
touched on above?
Thank you very much for any help.