http服务器可以处理多少个客户端? [英] How many clients can an http-server can handle?

查看:230
本文介绍了http服务器可以处理多少个客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个以Angular2作为客户端和NodeJS作为服务器的Web应用程序.我想在没有任何配置的情况下使用npm的http-server应用程序来提供服务,但是我想知道它可以同时处理多少个客户端?

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?

推荐答案

我决定进行一些基准测试,以便您可以在自己的服务器上运行 ,而不是推测,而是看看该问题的答案是什么以您的情况.我还将包括我在计算机上进行的那些测试的结果,这些结果非常有趣.

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:

创建一些新目录并安装http-server模块-如果您已经具有正在运行的服务器,则可以跳过此部分,但是我将其包含在此处,以便任何人都可以重复进行这些测试:

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

启动服务器

现在,您将必须启动服务器.我们将使用root来执行此操作,因为这样最容易增加打开文件的限制.

Starting the 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.

成为root用户,以后可以增加打开文件的限制:

Become root to be able to increase the open files limit later:

sudo -s

现在是root:

ulimit -a 100000

现在仍然以root身份运行服务器:

And now run the server, still as root:

./node_modules/.bin/http-server

或运行它,但是如果已经安装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

运行基准

现在,在另一个终端中,也成为root用户:

Running benchmarks

Now, in another terminal, become root as well:

sudo -s

您将需要从Apache安装 ab 工具.在Ubuntu上,您可以使用以下命令进行安装:

You will need to install the ab tool from Apache. On Ubuntu you can install it with:

apt-get install apache2-utils

现在,仍以root用户身份,增加打开文件的限制:

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/

这意味着要发出10,000个请求,其中10,000个(全部)同时发出.

Which means to make 10,000 requests, 10,000 of which (all of them) made concurrently.

我得到的结果是:

# 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)

回答您的问题

这是我在非常繁忙的系统上获得的可用空闲RAM很少的系统,因此您的行驶里程可能会有所不同.但是它同时提供了10,000个连接,因此您的问题的答案是:它可以处理很多请求,至少10,000个.我想知道您将能够在自己的服务器上实现什么-如果您得到一些有趣的结果,请发表评论.

Answer to your question

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.

如果使用http-server,则不必担心请求的复杂性,因为所有请求都将执行相同的操作-从磁盘提供单个静态文件.唯一的区别是文件的大小,但服务更大的文件不应在于可能的并发连接数,而应取决于传输数据的时间.

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.

结果很有趣,因为它显示了使用Node编写的简单服务器可以处理多少个连接.尝试使用Apache.

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.

这篇关于http服务器可以处理多少个客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆