Topic: Multithreaded vs Multiprocess  (Read 3022 times)

0 Members and 1 Guest are viewing this topic.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Multithreaded vs Multiprocess
« on: January 25, 2010, 03:36:12 pm »
I'm torn. I have a network code project to work on but I cannot decide on which route to go. Efficiency vs Stability. I'm leaning toward multi-process with the abundance of RAM and multicore processors these days...

Any thoughts?

edit: actually with abundant ram and multicore processors perhaps it is not a question of Efficiency vs Stability at all anymore? But rather convenience vs robustness? A large multithreaded app on a multicore processor could be less efficient than a multiprocess app...?
« Last Edit: January 25, 2010, 04:12:10 pm by Bonk »

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Multithreaded vs Multiprocess
« Reply #1 on: January 25, 2010, 06:26:52 pm »
I would go with multi-threading if you can see an improvement in performance.  Speed and efficiency should be the focus.  Stability I don't think will be an issue, as long as you follow the rules of programming multi-threaded.  Watch your mutexes and such.
The smell of printer ink in the morning,
Tis the smell of programming.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Multithreaded vs Multiprocess
« Reply #2 on: January 26, 2010, 02:53:27 pm »
Funny, I had just decided on multiprocess. (I thought)... Now I'm not so sure.

Basically, I'm biased by watching what has happened with web servers over the years. The trend is back to multiprocess.

I think what I need to figure out is the process creation overhead on windows.

It seems the issue is the lack of fork() on windows? Thus threads are better on windows? I do not want to go cygwin... but I so like the idea of fork().

Overall server design keeps creeping into my thoughts, I keep landing at a dumb multithreaded database for a server and instead of multiple processes handling connections and game logic per client serverside, just run it on the client. (easier on server resources too...) I need to think that through.... regardless they are going to need to talk over the network, and as I proposed perhaps that is just where I should focus for now as trying to conceive it all at once is rather overwhelming.

I like the idea of http tunneling. It is a waste of 30 years of network design, but hey, it is about all that is allowed/works now.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Multithreaded vs Multiprocess
« Reply #3 on: January 26, 2010, 03:04:22 pm »
Ah wait (dumb database concept aside for now) what I was thinking through last night was that with a webserver the speed of the establishment of connection is of paramount importance (thus the original drive to multithreaded servers, which as they grew in complexity and modularity grew unstable... so the apache MPM solution... which is appealing... )

Anyway, the point is that with gaming it does not really matter how long it takes to establish the initial connection (within reason here, were talking milliseconds to seconds here - not minutes or anything...), thus the overhead of process creation on the server (regardless of platform) is not so much an issue with a game server as it is with a web server. So what if it takes a few milliseconds more for a connection to be established, what matters is the efficiency of communication throughout the session.. thus the issue of process creation vs thread creation overhead is moot. As a result of using a multiprocess approach we can focus on game logic and let the operating system handle system resources as it is intended/designed to do.

I half expect that a multiprocess server would be more efficient on a multi processor machine than a multithreaded app... BUT... here's the big one, shared data... that is where the efficiency of a multiprocess approach may fall down with large player numbers... thus I keep coming back to the idea of ALL the logic running on the client and noting but a "database" server side.

(leaving out a master server list application of course... or is there a better approach on that? No, No... focus bonk, focus, just some network connection code for now, gotta start somewhere...)

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Multithreaded vs Multiprocess
« Reply #4 on: January 26, 2010, 03:37:37 pm »
for overall server I would look at one that does the lobby and places people in campaign games or pvp games.  This is then handed off to spawned servers to control the games themselves (not sure of the snuffiness of the servers this will be run on)
The smell of printer ink in the morning,
Tis the smell of programming.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Multithreaded vs Multiprocess
« Reply #5 on: January 26, 2010, 03:50:44 pm »
I think the solution for me at this early stage might be to try bare bones versions of both and see which might work out better for our purposes.

for overall server I would look at one that does the lobby and places people in campaign games or pvp games.  This is then handed off to spawned servers to control the games themselves (not sure of the snuffiness of the servers this will be run on)

I like the idea of listing PvP single session games publicly alongside campaign games. (with option for client to publish game to list or not).

Regarding individual campaign server specs, multiprocess could simplify the statement of specs... N clients will require X ram and Y processors...?


Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Multithreaded vs Multiprocess
« Reply #6 on: January 31, 2010, 06:17:10 am »
The trick is to find an approach that will work on windows and *nix. In searching for information on the topic today I landed here:

http://en.wikipedia.org/wiki/Process_%28computing%29
http://en.wikipedia.org/wiki/Process_management_%28computing%29

http://dev.chromium.org/developers/design-documents/multi-process-architecture
http://dev.chromium.org/developers/design-documents/inter-process-communication

Ah right! Chromium is a windows multiprocess application. Worth a little study. I really want to get started on this. I have a way of studying something to death and then it all starts to come together all of a sudden like. I'm hoping that will happen with this.

Two more relevant links:
http://www.osix.net/modules/article/?id=641
http://www.tenouk.com/ModuleR2.html  .. hey wait a minute... module R2? ;) <- this site has the info I want.
« Last Edit: January 31, 2010, 06:50:07 am by Bonk »