-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't create more than 64 client connections #449
Comments
OK... I have to ask... What use case are you looking at where you need to be simultaneously connected to more than 64 different MQTT brokers?!? :-) Honestly curious. The thinking when these libraries were created was that you would probably need one connection for a typical device; two for a bridge application; maybe a few more for something esoteric. So the thought was never for a large number of connections. But actually, this was question was discussed recently, in another GitHub issue, but I can't find it at the moment. It was either in this library, the Paho C lib, or the Rust one. This library and Rust both wrap the C lib. That's where the limit is likely getting hit, in the C lib. Or in the OS. What platform are you using? |
I am not connecting to more than 64 brokers, I am connecting more than 64 different clients to the same broker. The application is kind of complex, in summary it is for monitorization and control of simulated IoT devices and real physical models. For example, each simulated device needs to have a client_id and connection to the broker as a real device has, and also the interfaces that connect real/simulated devices require a connection to receive the real data and send instructions. I am using Windows, I could try on Linux, but I doubt there would be any difference, also the Python MQTT Paho library was able to connect 100 clients without problems, which I do not know if it also uses the C library. Any solution or help would be appreciated. |
Hmmm.... actually it may be a Windows issue after all. But first: I found the discussions about this. I could have sworn they happened this past spring, but it was actually a year and a half ago! First, someone mentioned that the Paho Rust client was crashing when trying to create more than 1,000 clients: I was able to verify this on Linux, but only after increasing my system/OS default limit of 1024 sockets per process. This led back to a related Issue in the Paho C lib: It turned out that C library was using the Version 1.3.10 of Paho C changed to use So, step #1 - Make sure you're using a recent version of the Paho C library. I recommend the latest v1.3.12. And then, according to my past self, you should theoretically be able to open at least 1,000 clients in a single app. If your OS allows it... The number 64 is exceedingly suspicious. I think you may be hitting a limit with Windows. I found this: https://learn.microsoft.com/en-us/windows/win32/winsock/maximum-number-of-sockets-supported-2
If that is the case, you might need to update the Paho C library source code to update the limit; probably with a build flag or something like that. But an easier solution would likely be to just use a *nix system like Linux or Mac. An alternate solution is to create an app that just opens one (or a few) connections, and then spawn as many instances of that app as you need to exercise your server. |
Oh, and the Python library is not based on the C lib. So its implementation is totally different and apparently not based on using |
Interesting! If it is platform related it might not be a problem since, even if this program is intended to run in a Windows Server for now, we are moving all our projects to Linux/Docker. |
You were correct @fpagliughi, it was a problem with Windows, the same code connected more than 64 devices on Linux (WSL). The next step is either migrating to Linux, or finding a way to increase that limit on Windows. I am going to try the second option first since apparently some parts of the service require to run on the Windows machine and migration is not so easy. I tried #define FD_SETSIZE 128 and other Windows configuration options, but did not make any difference, the 65th client onward fail to connect. I am open to any ideas or options that can be done to fix this limitation on Windows. |
Sorry I don't know. I'm not much of a Windows programmer myself. Did you set FDSET_SIZE in a rebuild of the Paho C library? It sounds like that might just be step 1 to get this to work. From that same page above:
Unfortunately I don't even have a Windows machine to test this out at the moment. But if you pursue the Windows idea and find a solution, please do update this issue. I will leave it open, then update the docs/README appropriately to help out the next person. Either way, let me know. |
@AlfonsoSanz Any resolution to this? |
Sorry @fpagliughi no solution on my part, the project was migrated to Linux where this limitation does not appear. |
OK. Thanks for reporting it and keeping up with it as long as you did! |
Clients after 64 connections return an MQTT error:
After creating 100 clients, if I try to connect them one by one to the broker, clients from 64 to 99 will give a Connect error [-1] on client.connect()->wait().
I can not find any option or solution to increase the amount of possible connections.
The text was updated successfully, but these errors were encountered: