PDA

View Full Version : QTcpServer - Multi thread or single?



December
8th February 2008, 07:49
I am playing with writing a server for handling basic IM type stuff between members of a website.

I have been reading a fair bit about multi vs single thread servers, and can't figure out which is the best approach when using QT. The examples that come with it show both!

1) A single event loop for everything
2) A couple of event loops (1 handle new connections, 1 Send Data, 1 Receive Data)
3) Spawn a new Thread for each client connecting.

My concerns with 1 and 2 would be that there could be delays while the thread is doing stuff. With 3 I am worried that the system would run out of resources quickly.. what is the typical max number of threads that can be open at one time?

Any one have a viewpoint on this?

wysota
8th February 2008, 09:30
For an IM I'd use a single thread. Even if you experience delays, they won't be noticable. How much clients do you expect to be connected? 100? That can surely be handled by a single thread.

December
8th February 2008, 10:05
Well the site has about 3000 users online at one time, but since the limit to open sockets is usually quite low, I will probably make each server only connect to 800 clients at once and then re-direct any more clients to the next server.

Is using QT for this type of task a good idea? I have heard good things about networking in QT, but this will be my first try at something like this.

wysota
8th February 2008, 10:31
Is using QT for this type of task a good idea? I have heard good things about networking in QT, but this will be my first try at something like this.

If you want a high level API then yes. If you want raw speed then using BSD sockets directly might be a better idea. If you are not experienced with socket programming, I'd go for a higher level interface.