Results 1 to 4 of 4

Thread: QTcpServer - Multi thread or single?

  1. #1
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTcpServer - Multi thread or single?

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer - Multi thread or single?

    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.

  3. #3
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTcpServer - Multi thread or single?

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer - Multi thread or single?

    Quote Originally Posted by December View Post
    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.

  5. The following user says thank you to wysota for this useful post:

    December (8th February 2008)

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  2. Replies: 10
    Last Post: 20th March 2007, 22:19
  3. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  4. Replies: 11
    Last Post: 7th July 2006, 13:09
  5. Multi thread problem
    By sreedhar in forum Qt Programming
    Replies: 5
    Last Post: 26th June 2006, 13:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.