views:

15

answers:

1

I'm designing a component to be run as a backend of a website. The component will take care of some AI logic, and I'm building it under C++. Would it be best if I let each session start a new EXE address space, or the EXE would be up and running and each session will start a new thread?

Or is there is any better suggestions alltogether?

A: 

I would be better to keep a process alive and create a new thread for each 'session': if you are looking for good performances under heavy load, starting a new process (fork, initialization of your app, etc.) will be really slow and can constitute a bottleneck.

Compared to that, creation of a new thread (in user space) is much lighter.

Even better, you can also keep the process running, and create a pool of threads. Then a 'manager' thread will process new connections, assign it to an existing thread and start it. In that case, you don't even need to create a new thread for each new connection. And if needed, the manager thread can adapt the number of existing threads to the load of your application.

Edit: This can be useful: Apache MPM model

Cedric H.