MongoDB connection limit

mongodb

I´m testing around with MongoDB and NodeJS. I´m stuck with the problem that I can create max 4899 connections to MongoDB. I´ve set the poolSize in the NodeJS Mongo driver to 40000.
Also I´ve set the needed ulimits of the mongo server.

Does anyone have an idea why the mongo server refuses new connections as soon
as 4899 are reached? The problem is definitely on th DB server side and not on client side.

I´m using the newest versions of all components (nodeJS V8, Mongo, Node mongo native driver)

limits configuration:

/etc/sysctl.conf
net.ipv4.ip_local_port_range = 1024 65000

/etc/security/limits.conf
mongodb         hard    nofile          1048576
mongodb         soft    nofile          1048576
mongodb         soft    nproc           1048576
mongodb         hard    nproc           1048576
mongodb         hard    stack           16384
mongodb         soft    stack           16384
mongodb         hard    memlock         unlimited
mongodb         soft    memlock         unlimited

/lib/systemd/system/mongodb.service
# (file size)
LimitFSIZE=infinity
# (cpu time)
LimitCPU=infinity
# (virtual memory size)
LimitAS=infinity
# (open files)
LimitNOFILE=500000
# (processes/threads)
LimitNPROC=500000

mongo serverstats:

db.serverStatus().connections
{
        "current" : 4899,
        "available" : 395101,
        "totalCreated" : NumberLong(5279)
}

Best Answer

Finally found the solution by myself:

in the systemd service configuration file /lib/systemd/system/mongodb.service set the following values to override the systemd tasklimit:

# (disable systemd tracking of number of tasks)
TasksAccounting=false

# (disable systemd tasklimit) possible values: infinity, a absolute number, or percentage of system wide limit
TasksMax=infinity