We have a database server application which consists of the followings components: 1) A service application with a database that accept w开发者_如何学Pythoneb service calls 2) A worker application (exe) which makes a web service request to the service application to get some work. Then it does some work and updates the database directly and then call another web service request to let the service application know that work has been finished.
We run a number of worker applications (in other words run the executable several times so there is more than one instance of it running) so each one can request work from the service application and carry on working without other workers applications interfering.
If I move this application a machine with multiple cores, is there a way of splitting the worker applications on different cores and at the same time have a service application on a different core?
Since I run the same application worker several times, apart from putting some code in that checks how many instances of it are running on different cores, I cannot see how I can do this.
In past tests, I see all the worker applications running and the service application running on the same core, which is maxing it out while I have 3 cores doing nothing.
Any ideas?
JD.
Not a good idea to manually force each application run over a specific core. There are multiple issues.
What if you moved to another machine with two cores (changing the code is not a good idea).
You will create bottlenecks for your application because there are other system tasks for operating system and also there are other applications on the same machine and your application on core 3 is waiting for a time-slice while core 2 is free, but you told OS
to run it over core 3. You don't have control over external factors. Remember OS
will use sophisticated algorithms for task scheduling and its hard to do it better than OS
.
WHat I suggest is using Task Library
of .NET 4.0
inside your application. It would decide how to use multiple cores of your machine in an effective way.
In past tests, I see all the worker applications running and the service application running on the same core, which is maxing it out while I have 3 cores doing nothing.
This is a funxdamental issue in your programming then. THe workers are separate processes = separate threads, so they get distributed per definition.
If you ahve 4 of them, and 1 is doing all the work and 3 are idle, it could be that:
- Your workers are blocking, so while one works for exampel the db locks the others, so they are handling a request but working for one to finish. For exmaple because of database locking.
- Your work distribution is faulty, in that for example the server sends all requests to one worker instead of distributing it. In this case the additional workers are basically redundant baggage you carry around.
Both are NOT OS issues. The OS normally will distribute threads to cures, and multiple processes are multiple threads, so they do get distributed per default.
One thing that could for example be wrong is that your service application is NOT multi threaded, so while it can distribute the load to workers, it only processes one reuest always (this could bea configuration / web service settings issue). THis would naturally mean only one process always ever gets processed from there. Seen that happening.
To be honest, if you're planning on rewriting it to support multiple cores, use the multithreading in .NET4 for this, it would be a better abstraction of your application - rather than one instance of an app per task, have one app executing all the tasks using asynchronous threading, which will automatically get processed across multiple cores. Just my /2c.
精彩评论