I built a web application with Angular2 as client and NodeJS as server. I want to serve it with npm's http-server
application without any configuration but I wonder how many clients it can handle simultaneously?
This restriction is defined in the HTTP specification (RFC2616). Most modern browsers allow six connections per domain. Most older browsers allow only two connections per domain. The HTTP 1.1 protocol states that single-user clients should not maintain more than two connections with any server or proxy.
CPU Cores. A Single CPU core will commonly handle an average of 220 to 250 concurrent connections simultaneously. If for instance, a website runs on a server that has a single CPU with 2 CPU cores, approximately 500 visitors may access and search the website at the same time.
How is it different from other types of servers? Why do big sites use multiple servers instead of one server with better specifications? Google processes 40k searches per second. On average, a web server can handle 1000 requests per second.
By default each Cloud Run container instance can receive up to 80 requests at the same time; you can increase this to a maximum of 1000. Although you should use the default value, if needed you can lower the maximum concurrency. For example, if your code cannot process parallel requests, set concurrency to 1 .
Instead of speculating I decided to make some benchmarks that you can run on your own server, to see what's the answer to that question in your case. I will also include the results of those tests that I got on my computer which are quite interesting.
First, what I did and how anyone can repeat it:
Make some new directory and install the http-server
module - this part can be skipped if you already have a running server but I included it here so anyone could repeat those tests:
mkdir httptest
cd httptest
npm install http-server
Now you will have to start the server. We'll do it with root because that way it will be easiest to increase the open files limit.
Become root to be able to increase the open files limit later:
sudo -s
Now as root:
ulimit -a 100000
And now run the server, still as root:
./node_modules/.bin/http-server
or run it however you would normally run if you have http-server
already installed.
You should see something like:
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
Now, in another terminal, become root as well:
sudo -s
You will need to install the ab
tool from Apache. On Ubuntu you can install it with:
apt-get install apache2-utils
Now, still as root, increase the open files limit:
ulimit -n 100000
And start the benchmark with:
ab -n 10000 -c 10000 -k http://localhost:8080/
Which means to make 10,000 requests, 10,000 of which (all of them) made concurrently.
The result I got was:
# ab -n 10000 -c 10000 -k http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:
Server Hostname: localhost
Server Port: 8080
Document Path: /
Document Length: 538 bytes
Concurrency Level: 10000
Time taken for tests: 17.247 seconds
Complete requests: 10000
Failed requests: 0
Keep-Alive requests: 0
Total transferred: 7860000 bytes
HTML transferred: 5380000 bytes
Requests per second: 579.82 [#/sec] (mean)
Time per request: 17246.722 [ms] (mean)
Time per request: 1.725 [ms] (mean, across all concurrent requests)
Transfer rate: 445.06 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 255 321.2 141 1000
Processing: 143 2588 1632.6 3073 16197
Waiting: 143 2588 1632.7 3073 16197
Total: 143 2843 1551.8 3236 17195
Percentage of the requests served within a certain time (ms)
50% 3236
66% 3386
75% 3455
80% 3497
90% 3589
95% 3636
98% 3661
99% 3866
100% 17195 (longest request)
This is what I got on a very busy system with very little free RAM available so your mileage may vary. But it served 10,000 connections at the same time so the answer to your question is: it can handle a lot of requests, at least 10,000. I wonder what you will be able to achieve on your own server - please comment if you get some interesting results.
If you use http-server
then you don't have to worry about complexity of the requests because all of them will do the same thing - serve a single static file from the disk. The only difference would be the size of the files but serving bigger files should not be in the number of possible concurrent connections but with the time it takes to transfer the data.
You should make those tests on your own real files that you're actually serving so that you could see the numbers for your own specific case.
The results are interesting because it shows how many connections you can handle with such a simple server written in Node. Try that with Apache.
The maximum throughput depends of the hardware you are using and complexity of the requests (cpu/io/eventloop blocks...).
You can measure it yourself with some http benchmark tools or find some examples here: https://raygun.com/blog/2016/06/node-performance/
Some http benchmark tools:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With