pthread_create failed: errno:11 Resource temporarily unavailable

4,159 views
Skip to first unread message

Darshan Shah

unread,
May 5, 2016, 10:08:28 AM5/5/16
to mongodb-user
Hi,

Intermittently I see the below error message in the logs:
2016-05-05T08:11:03.408-0400 I NETWORK  [initandlisten] pthread_create failed: errno:11 Resource temporarily unavailable
2016-05-05T08:11:03.408-0400 I NETWORK  [initandlisten] failed to create thread after accepting new connection, closing connection

This message is continuously printed multiple times in the log and then everything seems to be fine after 15-30 seconds. This pattern recurs at varying intervals in the log several times.

I am running MongoDb 3.2.5 WiredTiger with --wiredTigerCacheSizeGB 20 on CentOS 7.1 and the setup is 3 config servers, 28 shards with each shard being a 3 node replicaset and 30 mongos processes. The mongo related processes are started with numactl --interleave=all 

The limits on the boxes have been cranked up as below:
$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 1546963
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 131072
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

$ cat /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited

oasprod soft nofile unlimited
#oasprod hard nofile 65535
oasprod hard nofile 131072
oasprod soft nproc unlimited
oasprod hard nproc unlimited
oasprod soft fsize unlimited
oasprod hard fsize unlimited
oasprod soft memlock unlimited
oasprod hard memlock unlimited
oasprod soft cpu unlimited
oasprod hard cpu unlimited
oasprod soft as unlimited
oasprod hard as unlimited

# Sample limits of a Mongod process
$ cat /proc/44954/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             unlimited            unlimited            processes
Max open files            131072               131072               files
Max locked memory         unlimited            unlimited            bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       1546963              1546963              signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

Other parameters of the system are:
$ cat /proc/sys/net/ipv4/ip_local_port_range
32768   61000

$ cat /proc/sys/vm/max_map_count
65530

$ cat /proc/sys/net/ipv4/tcp_keepalive_time
35

$ cat /proc/sys/kernel/threads-max
3093926



All help is highly appreciated!
Thanks!

Darshan Shah

unread,
May 11, 2016, 9:18:01 AM5/11/16
to mongodb-user
Another observation - this happens randomly with either MongoS, Primary MongoD, Secondary MongoD or Arbiter MongoD and sometimes the problem lasts longer over a few minutes too.

Thanks!

Wan Bachtiar

unread,
May 19, 2016, 10:38:31 PM5/19/16
to mongodb-user

pthread_create failed: errno:11 Resource temporarily unavailable

This message is continuously printed multiple times in the log and then everything seems to be fine after 15-30 seconds.

Hi Darshan,

Generally the error message is an indication that the OS runs out of sockets for mongod to open (pthread_create returns EAGAIN see linux pthread_create:ERRORS).

$ cat /proc/sys/kernel/threads-max
3093926

Based on your /proc/sys/kernel/threads-max, you have increased the maximum number of threads on the system to be 3093926. Depending on your hardware specs and applications requirements, you need to ensure that this is a reasonable number. Try tuning the number of maximum threads accordingly.

$ cat /etc/security/limits.d/20-nproc.conf

  • soft nproc 4096
    root soft nproc unlimited

Based on the output of /etc/security/limits.d/20-nproc.conf, although you have the root user setting to unlimited, generally mongod in CentOS is executed via mongod user. Check whether the mongod process is actually under the soft limits of 4096.

Another thing to check, sometimes multiple short-lived connections can caused the machine to reach the system limits. Check on how your applications utilise the connections. i.e. depending on your use case see Bulk() operations.

You may also be benefited from reading these deployments/operational resources:

Kind regards,

Wan.

Reply all
Reply to author
Forward
0 new messages