diff --git a/lokimq/lokimq.cpp b/lokimq/lokimq.cpp index 930f7c1..e659fb2 100644 --- a/lokimq/lokimq.cpp +++ b/lokimq/lokimq.cpp @@ -237,6 +237,12 @@ void LokiMQ::start() { LMQ_LOG(info, "Initializing LokiMQ ", bind.empty() ? "remote-only" : "listener", " with pubkey ", to_hex(pubkey)); + int zmq_socket_limit = context.getctxopt(ZMQ_SOCKET_LIMIT); + if (MAX_SOCKETS > 1 && MAX_SOCKETS <= zmq_socket_limit) + context.setctxopt(ZMQ_MAX_SOCKETS, MAX_SOCKETS); + else + LMQ_LOG(error, "Not applying LokiMQ::MAX_SOCKETS setting: ", MAX_SOCKETS, " must be in [1, ", zmq_socket_limit, "]"); + // We bind `command` here so that the `get_control_socket()` below is always connecting to a // bound socket, but we do nothing else here: the proxy thread is responsible for everything // except binding it. diff --git a/lokimq/lokimq.h b/lokimq/lokimq.h index 9c66e3a..656a1a5 100644 --- a/lokimq/lokimq.h +++ b/lokimq/lokimq.h @@ -196,6 +196,11 @@ public: * disconnected. -1 means no limit. */ int64_t MAX_MSG_SIZE = 1 * 1024 * 1024; + /** Maximum open sockets, passed to the ZMQ context during start(). The default here is 10k, + * designed to be enough to be more than enough to allow a full-mesh SN layer connection if + * necessary for the forseeable future. */ + int MAX_SOCKETS = 10000; + /** Minimum reconnect interval: when a connection fails or dies, wait this long before * attempting to reconnect. (ZMQ may randomize the value somewhat to avoid reconnection * storms). See RECONNECT_INTERVAL_MAX as well. The LokiMQ default is 250ms.