⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)
[SOLVED] QTcpServer max connection limit
what is the maximum QTcpServer connection limit?
Are you asikng about "pending connections limit":http://doc.qt.nokia.com/4.7/qtcpserver.html#setMaxPendingConnections ? Or you are asking about total limit of open sockets? In second case it is up to OS.
total limit of open sockets.
koahnig last edited by
I guess you mean "this":http://doc.qt.nokia.com/4.7/qtcpserver.html#setMaxPendingConnections
This is not a max connection, but a maximum pending connection limit.
In my opinion for practical reasons. When your server connection is not able to respond and establish all pending connections, you will run into problems. The default value is already quite a large number. When you have something trying to block your application, it becomes already quite busy.
Edit: Typed too long ;-)
As I said total limit of open sockects is up to OS. Qt can do nothing here.
Not only depends on the OS, but on the used strategy for handling each connection request/processing/response, there are multiple strategies: the ones I've used in the past are thread per connection, reactor, proactor.
Does anyone know which strategy Qt uses for it's server network connection handling? it really matters because it can range from being able to support a few hundred simultaneous connections at most (thread per connection) to more than 10,000-20,000 (proactor, native use of non-blocking async from the OS), so it really makes a huge difference.
Raul, QTcpServer ONLY creates a socket object for you, nothing more. All further handling is up to you.
Yes, I mentioned all of the above so that the devs knows the OS doesn't magically handle a max load of connections, but that it has to implement a connection strategy.
Also, for that, If you know your way around a bit the boost library, you can get libraries that already implement those strategies, and you just have to give it the transports (in this case QTcpServer).
Each strategy helps you handle more connections but also grows in complexity, let's say, thread per connection gives you only a couple of hundred connections but it's easier to handle than let's say, the proactor, which can manage tens of thousands of simultaneous connections, but because it's fully asynchronous in nature, and also is implemented through multiple classes, it's much harder to use.
Raul, you said that thread per connection gives you only a couple of hundred connections. is it true that the Tcp Server can be written for single thread or multiple threads connections? I need more information about this topic.
I am also looking for tcp/ip tutorials or working examples.
I don't know how Qt's tcp server works, I don't really use it, instead I use poco's reactor with it's tcp implementation (pocoproject.net), I like it because of it's simplicity, and reactor gives you a couple thousand concurrent connections, it uses async strategies for handling the sockets, but sync for talking to the working threads, so it's a midpoint between thread per connection and proactor.
I don't care about handling tens of thousands of concurrent connections, as for that kind of stuff I use something more enterprise server oriented like java EE 6 with glassfish.
I'm mostly using Qt for UI only, and I'm starting to learn and use QML, which by the way, I'm really starting to enjoy :)
Mix and matching qwidgets with QML you can achieve some really cool desktop apps. I do want to learn a lot more about Qt, but for the time being, and the work demand I have on my current job, I haven't been able to learn Qt further, as I use it for personal stuff, and on the job I use mostly java for highly concurrent servers (check out apache mina or project grizzly and java's NIO if java interests you), that's why I know quite a bit about connection handling and concurrency.
For more on the subject, learn about poco here: "Poco documentation":http://pocoproject.org/documentation/index.html
and even further, check out the network programming slides: "Network Programming":http://pocoproject.org/slides/200-Network.pdf
Hope it helps, I don't know where to get more info on the subject for Qt, but I already preordered the ebook for Introduction to Design Patterns in C++ with Qt 2nd Edition from informit.com, it was gonna be released on july 31st but I just got notified that it's delayed 'till at least september 6th, I don't know if has something on network programming, but I hope I learn enough about Qt to be able to browse the source better and understand more about the subject.
goetz last edited by
The limit on the number of sockets is set by the OS. In the end everything boils down to BSD sockets and it's quite irrelevant for that aspect what type of pattern you put on top of that. This holds for poco's reactor too.
Regarding the overall performance and ressource consumption of an application, it does matter which pattern you use, of course :-)
Yeah but you're going way too low level to say that everything boils down to just sockets (and not BSD sockets if you're on windows :), it's like saying it boils down to the hardware layer, and on desktop you get enough resources to be able to handle a very decent amount of sockets, to worry about that it means you are on a very limited hardware (like embedded devices), so that's why on the desktop It's more relevant on how you consume resources for processing what you receive on the socket, rather than just worrying about the socket itself.
Raul, it is not good advice to NOT worry about resources (even on desktops). A small error and you will go out from resources very quickly (for example if you will forgot to close and dispose your socket that is created in loop)
You're right, even though on desktop you have 65,500 (give or take a few hundred) ports to choose for your sockets, I'm guessing you will be out of memory if you don't deallocate your working objects before you run out of sockets.
And yes, forgetting to close your socket can cause you leaks, just like forgetting to cleanup any other unused object in your app.
goetz last edited by
The original question was:
[quote author="kalster" date="1312611841"]what is the maximum QTcpServer connection limit?[/quote]
That basically boils down to the OS level and is more or less independent from the frameworks and/or patterns you put on top. The latter may help in speeding up the processing of the requests of course.