Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multithreaded/Multiprocess Application

Started by tstrimp Jul 11, 2006 at 8:19 AM 3 replies 2.6k views
Original Post
tstrimp
tstrimp
The software I'm working on is a client/server model that we hope to keep the server cross-platform compatible. One situation we hope to avoid of course is one client that needs a lot of processing or disk access and they prevent other clients from processing until it is done. I've looked into boost.threads a little for multithreading the application and have a few questions reguarding that, but first I was wondering which would be better to use. Multi-threading or multi-process? From what I have gathered multi-process is where instead of threads a server would spawn separate application instances in order to handle multiple requests like apache does. To me spawning children to handle the requests would be a safer and more elegent solution since each client has it's own application space and a crash shouldn't effect all of the clients. I was interested in trying to prototype a client/server where the server spawned child processes for handling but I can't seem to find a cross-platform C++ library for actually spawning child processes. Does anyone know of a library that does this? Is this even the best method to use or should I stick to multi-threading?
Prozak
Prozak
It would seem to me that inter-process sharing of data would be far more complex that inter-thread sharing of data.

If done right, there is nothing to fear from threads. Just make sure that you don't leave them in busy loops.

Regarding crashes, if a process crashes and only brings down itself, leaving the other clients untouched, then that is a big plus, on the other hand I believe in "pounding away" at the errors.

If your clients are crashing then you're not handling data correctly at some point in your code. Be it a process or a thread doesnt change the fact that to increase your code's reliability you'll have to go in and debug it.

So, in my opinion I would go with threads, they'll do what you require, and there is a lot of resources around that explain how to deal with lockouts, busy loops, etc...

Good luck! [wink]
tstrimp
tstrimp
Thanks for the input! I'll probably lean that way but I also thought I'd throw out there that a client could potentially take a lot of server time. What would the impact on that be in threads vs processes? A client could take several minutes for a single request, though that would be rare. From what I've read (since I have no experience dealing with either method) a process method is better if the client will be taking an extended period of time to complete the request.
Prozak
Prozak
Well, from the little that I know, and I hope I'm not wrong on this, but I think Windows prioritizes first by processes and then by threads.

This means that a process deemed of high importance will receive more processing time that another of average importance.

The same goes for threads, but threads are organized per process, therefore a medium importance thread on a low importance process will receive less processing time than a low importance thread on a high importance process.

It seems that, more than looking at processes or threads, what you need to look at is a resource manager, responsible for generating "work units" that clients can work on.

I could tell you to just spawn as many threads as there is work to be done, but thruthfully, if you're working on 10 diferent things, and you have 10 work threads, all of them reading from and writing to the drive, then they're colliding between themselfs, and competing for resources (drive time).

It's the Resource Manager's responsability to manage work in such a way that there will never be competition for a vital resource. 10 worker threads all accessing the drive at the same time will take longer than 2 worker threads in parallel, spawned 5 times, because in the first example, much time will be lost between threads waiting for the "drive resource" to be freed so they can write/read.

Hope that helped...
mikeman
mikeman
I'm not sure, but I *think* you could design an AbstractClient module that has all the methods a typical client would need(creation,communication...), and expose to the server that class. You then derive from AbstractClient and implement ThreadClient or ProcessClient which the server can use transparently. Then it's up to you and the needs of the application to decide whether the particular client will use a new thread or a new process.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.