Erlang's maximum number of simultaneous open ports? - erlang

Does the erlang TCP/IP library have some limitations? I've done some searching but can't find any definitive answers.
I have set the ERL_MAX_PORTS environment variable to 12000 and configured Yaws to use unlimited connections.
I've written a simple client application that connects to an appmod I've written for Yaws and am testing the number of simultaneous connections by launch X number of clients all at the same time.
I find that when I get to about 100 clients, the Yaws server stops accepting more TCP connections and the client errors out with
Error in process with exit value: {{badmatch,{error,socket_closed_remotely}}
I know there must be a limit to the number of open simultaneous connections, but 100 seems really low. I've looked through all the yaws documentation and have removed any limit on connections.
This is on a 2.16Ghz Intel Core 2 Duo iMac running Snow Leopard.
A quick test on a Vista Machine shows that I get the same problems at about 300 connections.
Is my test unreasonable? I.e. is it silly to open 100+ connections simultaneously to test Yaws' concurrency?
Thanks.

It seems you hit a system limitation, try to increase the max number of open files using
$ ulimit -n 500
Python on Snow Leopard, how to open >255 sockets?
Erlang itself has a limit of 1024:
From http://www.erlang.org/doc/man/erlang.html
The maximum number of ports that can be open at the same time is 1024 by default, but can be configured by the environment variable ERL_MAX_PORTS.
EDIT:
The system call listen()
has a parameter backlog which determines how many requests can be queued, please check whether a delay between requests to establish connections helps. This could be your problem.

All Erlang system limits are reported in the Erlang Efficiency Guide:
http://erlang.org/doc/efficiency_guide/advanced.html#id2265856
Reading from the open ports section:
The maximum number of simultaneously
open Erlang ports is by default 1024.
This limit can be raised up to at most
268435456 at startup (see environment
variable ERL_MAX_PORTS in erlang(3))
The maximum limit of 268435456 open
ports will at least on a 32-bit
architecture be impossible to reach
due to memory shortage.

After trying out everybody's suggestion and scouring the Erlang docs, I've come to the conclusion that my problem is with Yaws not being able to keep up with the load.
On the same machine, an Apache Http Components web server (non-blocking I/O) does not have the same problems handling connections at the same thresholds.
Thanks for all your help. I'm going to move on to other erlang based web servers, like Mochiweb.

Related

EMQX Benchmarking Issue

Is it possible to test the WebSocket connection test for 100k users on single node? If yes, how?
I am wondering how the 1 million connection test per node was carried out as claimed on EMQX official site.
If the port limit of OS itself is 65536
The server only needs one port.
The clients port limit of the operating system can be bypassed (using multiple network cards in ). You can use JMeter to test the connection. In order to simulate the client, multiple servers may be required. Here is an EMQ official video, which gives some operating procedures.
https://www.bilibili.com/video/BV1yp4y1S7zb

How to monitor windows service and process with zabbix

I am new in Zabbix and I am using Zabbix 3.4 version. I have installed server on Linux and want to monitor and check status of Windows service using its Windows agent.
I got the status of services using the key below
service.info[<serviceName>,state]
It returns me proper status of service. Now I want to check how much CPU is utilized by process and how much memory is utilized by process.
I tried some of keys but it's not returning proper value.
perf_counter[\Process(<processName>)\% User Time] // to get CPU utilization by process
proc_info[<processName>,wkset] // to get memory utilize by process
system.cpu.util[,system,avg5] // to get total CPU utilization
vm.memory.size[available] // to get total RAM utilization
But none of above working properly. I tried other keys also but agent logs say it's unsupported. I checked forum and searched on Google but nothing found.
Usually there isn't a direct match Windows Service -> Specific process.
Any service spawns N processes for its internals and also can spawn additional processes to manage incoming connection, log requests and so on.
Think about a classic httpd server: you should find at least one master process, various pre-forked server processes and php/php-fpm processes for current requests.
Regarding the keys you provided, what do you mean by "not working properly" ?
You can refer to Zabbix documentation for Windows-specific items for the exact syntax of the items and the meaning of the return values.
You can use Zabbix item for CPU Utilization of average 5 min:
system.cpu.util[,,avg5]
This will give you average usage of CPU per 5 mins on Windows server. You can then create an appropriate trigger for the same.

What's the risk in setting the Postgres connection pool size too high?

I am running a tonne of jobs in parallel using Sidekiq and a lot of them are failing to connect to the database because I've only got a connection pool size of 5.
I'd like to just bump that up to 15 (at least on localhost) but was wondering what the possible negative consequences of that might be.
Setup is Ruby on Rails, default poolsize is 5.
It depends on many factors like:
how much memory you want to allocate to your database pool
how long your connections last
the timeout on the connections
the locality of your database server compared to your app/web server
There are other tweaks that some connection pools have also such as the minimum number of connections to have open (even if not used), and the maximum open connections which looks like what you are trying to set.
I have heard that you can potentially saturate your network card with as little as 10 open connections.
I think the only answer is to monitor your cpu/memorry/io usage based on what you have so you have some sort of a baseline, and then bump the connection count up and compare.
Personally I think you should be fine with 15 connections assuming you arent' already pushing your server to the limit or have a tiny VM with 256MB of ram :)
Setting the value too high could saturate the # of allowable open connections to postgres (check the default but it may be around 100). This could especially be a problem if you prematurely shut your services down without allowing it to gracefully close the connections. Then when you try and restart your app server it will error out saying that postgres is not allowing any more connections. This isn't a problem of setting it too high as this would happen in either case but it would def. accelerate the issue.

Maximum socket Connection with epoll

I'm using CentOS (Linux) and was wondering
the maximum connection that one server can have through epoll (Edge Trigger, OneSHot) .
I've succeeded in having 100,016 connections doing ping-pongs (nonstop) atm. How many socket connections can one server handle?
I don't think it is unlimited. If anyone who've tried it. Could you please share ?
500,000 TCP connections from a single server is the gold standard these days. The record is over a million. It does require kernel tuning. See, for example, Linux Kernel Tuning for C500k.

while tesing, I got erlang_error: "{badmatch,{error,system_limit}},{module,function,3}"?

I am doing load testing of my server with number of clients(200, 300, 500, ....3000). For testing I am using windows 64 bit systems and I am running server on one system and clients on another system. All the clients can do connections successfully, but after one minute or two minutes later, server through an erlang:error -> "{badmatch,{error,system_limit}},{module,accept_function,3}" for some server instances and dies those server instances. Can any on have a solution for this ?
Thank you in advance..
sreenivas, India.
It appears that you have hit the system limit on the number of ports you are allowed to open on your system. Have a read of this doc here to see if you can determine what your limits are.
In particular:
Open ports The maximum number of
simultaneously open Erlang ports is by
default 1024. This limit can be raised
up to at most 268435456 at startup
(see environment variable
ERL_MAX_PORTS in erlang(3)) The
maximum limit of 268435456 open ports
will at least on a 32-bit architecture
be impossible to reach due to memory
shortage.
Open files, and sockets The maximum
number of simultaneously open files
and sockets depend on the maximum
number of Erlang ports available, and
operating system specific settings and
limits.

Resources