国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[譯]Loadtest庫(kù)做負(fù)載測(cè)試

asoren / 1902人閱讀

摘要:在選定的或者上進(jìn)行負(fù)載測(cè)試,允許在你自己的測(cè)試?yán)镙p松集成。使用提供的非常容易整合到你的包里進(jìn)行編程負(fù)載測(cè)試。在部署新版本軟件之前,使運(yùn)行負(fù)載測(cè)試成為系統(tǒng)測(cè)試的一部分變得非常容易。

前言

因?yàn)樽罱鼘W(xué)習(xí)需要用到一些測(cè)試庫(kù)測(cè)試性能,但是工具又太復(fù)雜不好用,恰好發(fā)現(xiàn)有這么一個(gè)庫(kù)用法輸出都很近似,可惜沒有找到有中文版或者用法筆記,所以只好耐心一點(diǎn)一點(diǎn)翻譯出來(lái)。因?yàn)槲业挠⑽乃胶芤话悖@種技術(shù)博客直接機(jī)翻是表達(dá)不出意思的,只能硬著頭皮按自己理解寫出來(lái),為了不誤人誤己,我在原文底下翻譯,這樣大家也可以直接看原文。
全文加起來(lái)一萬(wàn)八字,原文大概就九千字吧,如果嫌界面排版難看的直接去原文吧。
loadtest
有些地方真的不知道怎么翻譯,有能力的麻煩指正一下。

loadtest
Runs a load test on the selected HTTP or WebSockets URL. The API allows for easy integration in your own tests.

在選定的HTTP或者WebSockets URL上進(jìn)行負(fù)載測(cè)試,API允許在你自己的測(cè)試?yán)镙p松集成。

Installation
Install globally as root:

全局安裝

# npm install -g loadtest
On Ubuntu or Mac OS X systems install using sudo:

在Ubuntu 或者 Mac OS X系統(tǒng)安裝使用 sudo

$ sudo npm install -g loadtest
For access to the API just add package loadtest to your package.json devDependencies:

想要訪問(wèn)API只需要在package.json里的devDependencies添加loadtest

{
    ...
    "devDependencies": {
        "loadtest": "*"
    },
    ...
}
用法
Why use loadtest instead of any other of the available tools, notably Apache ab?
loadtest allows you to configure and tweak requests to simulate real world loads.

為什么使用loadtest替代其他的可用工具,尤其是Apache ab
loadtest 允許你配置和調(diào)整請(qǐng)求去模擬真實(shí)世界的負(fù)載。

基礎(chǔ)用法
Run as a script to load test a URL:

作為腳本執(zhí)行去負(fù)載測(cè)試URL:

$ loadtest [-n requests] [-c concurrency] [-k] URL
The URL can be "http://", "https://" or "ws://".
Set the max number of requests with -n, and the desired level of concurrency with the -c parameter.
Use keep-alive connections with -k whenever it makes sense,
which should be always except when you are testing opening and closing connections.

URL可以是"http://", "https://" 或者 "ws://".
-n設(shè)置最大請(qǐng)求數(shù),
-c設(shè)置并發(fā)級(jí)別,
除了測(cè)試打開和關(guān)閉連接以外有意義的時(shí)候可以用-k做長(zhǎng)連接。

Single-dash parameters (e.g. -n) are designed to be compatible with
Apache ab,
except that here you can add the parameters after the URL.

單破折號(hào)參數(shù)(例如-n)被設(shè)計(jì)為可兼容Apache ab,除了你可以在URL后面添加參數(shù)。

To get online help, run loadtest without parameters:

想要獲取線上幫助,運(yùn)行l(wèi)oadtest不帶參數(shù):

$ loadtest
用法文檔
The set of basic options are designed to be compatible with Apache ab.
But while ab can only set a concurrency level and lets the server adjust to it,
loadtest allows you to set a rate or requests per second with the --rps option.

基本設(shè)置選項(xiàng)被設(shè)計(jì)為可兼容Apache ab,然而ab只能設(shè)置并發(fā)級(jí)別讓服務(wù)端調(diào)整它。loadtest允許你用--rps選項(xiàng)設(shè)置每秒速率或請(qǐng)求數(shù)(后面統(tǒng)稱rps)。

Example:

loadtest -c 10 --rps 200 http://mysite.com/
This command sends exactly 200 requests per second with concurrency 10, so you can see how your server copes with sustained rps. Even if ab reported a rate of 200 rps, you will be surprised to see how a constant rate of requests per second affects performance: no longer are the requests adjusted to the server, but the server must adjust to the requests! Rps rates are usually lowered dramatically, at least 20~25% (in our example from 200 to 150 rps), but the resulting figure is much more robust.

這個(gè)命令在10并發(fā)量情況下每秒發(fā)送200個(gè)請(qǐng)求,所以你能看到你的服務(wù)端怎么處理持續(xù)的rps。即使是ab報(bào)告的速率是200rps,你也會(huì)驚奇地看到每秒請(qǐng)求的恒定速率怎么影響性能;不再調(diào)整請(qǐng)求到服務(wù)器,但是服務(wù)器必須調(diào)整到請(qǐng)求! Rps率通常會(huì)大幅降低至少20~25%(在我們的例子200-150rps),但由此得出的數(shù)據(jù)要穩(wěn)健得多。
(有點(diǎn)繞,不知道怎么翻)

loadtestis also quite extensible. Using the provided API it is very easy to integrate loadtest with your package, and run programmatic load tests. loadtest makes it very easy to run load tests as part of systems tests, before deploying a new version of your software. The results include mean response times and percentiles, so that you can abort deployment e.g. if 99% of the requests don"t finish in 10 ms or less.

loadtest是可擴(kuò)展的。使用提供的API非常容易整合loadtest到你的包里進(jìn)行編程負(fù)載測(cè)試。在部署新版本軟件之前,loadtest使運(yùn)行負(fù)載測(cè)試成為系統(tǒng)測(cè)試的一部分變得非常容易。
結(jié)果包括平均響應(yīng)時(shí)間和百分比,以便你可以終止部署,例如,如果99%的請(qǐng)求在10毫秒或更短的時(shí)間內(nèi)沒有完成。

注意事項(xiàng)
loadtest saturates a single CPU pretty quickly.
Do not use loadtest if the Node.js process is above 100% usage in top, which happens approx. when your load is above 1000~4000 rps.
(You can measure the practical limits of loadtest on your specific test machines by running it against a simple
Apache or nginx process and seeing when it reaches 100% CPU.)

loadtest會(huì)很快使單個(gè)CPU飽和。
如果Node.js使用率已經(jīng)超過(guò)100%不要使用loadtest,當(dāng)你負(fù)載超過(guò)1000~4000rps會(huì)發(fā)生類似的事。
(你可以運(yùn)行指定的測(cè)試機(jī)器測(cè)量loadtest的實(shí)際極限通過(guò)簡(jiǎn)單的Apache 或者 nginx進(jìn)程查看什么時(shí)候達(dá)到100%CPU。

There are better tools for that use case:

這些是使用示例更好的工具

Apache ab has great performance, but it is also limited by a single CPU performance.Its practical limit is somewhere around ~40 krps.

weighttp is also ab-compatible and is supposed to be very fast (the author has not personally used it).

wrk is multithreaded and fit for use when multiple CPUs are required or available.It may need installing from source though, and its interface is not ab-compatible.

ab性能優(yōu)異,但是總是受限于單個(gè)CPU性能,它的實(shí)際極限大概40krps。

weighttp可以兼容ab并且快速支持(作者沒有用過(guò))

wrk 是多線程的,適合在需要或可用多個(gè)cpu時(shí)使用,它可能需要安裝源文件并且不兼容ab

常規(guī)用法
The following parameters are compatible with Apache ab.

下面參數(shù)兼容Apache ab.

-n requests
Number of requests to send out.

發(fā)送請(qǐng)求數(shù)量

Note: the total number of requests sent can be bigger than the parameter if there is a concurrency parameter;loadtest will report just the first n.

注意:如果有并發(fā)參數(shù),發(fā)送的請(qǐng)求總數(shù)可以大于參數(shù);loadtest將只報(bào)告第一個(gè)n
(我猜這里意思是前一個(gè)n也就是發(fā)送的請(qǐng)求總數(shù))

-c concurrency
loadtest will create a certain number of clients; this parameter controls how many.
Requests from them will arrive concurrently to the server.

loadtest會(huì)創(chuàng)建一定數(shù)量的客戶端,這參數(shù)控制具體多少。
它們的請(qǐng)求會(huì)并發(fā)到達(dá)服務(wù)端。

Note: requests are not sent in parallel (from different processes),
but concurrently (a second request may be sent before the first has been answered).

注意:請(qǐng)求實(shí)際上沒有并行發(fā)送(來(lái)自不同的進(jìn)程),
但是并發(fā)(第二個(gè)請(qǐng)求在第一個(gè)請(qǐng)求響應(yīng)之前發(fā)送)

(并行是指兩個(gè)或者多個(gè)事件在同一時(shí)刻發(fā)生;而并發(fā)是指兩個(gè)或多個(gè)事件在同一時(shí)間間隔發(fā)生,同時(shí)與交替的區(qū)別。)

-t timelimit
Max number of seconds to wait until requests no longer go out.

等待直到請(qǐng)求不再發(fā)送的時(shí)間

Note: this is different than Apache ab, which stops receiving requests after the given seconds.

注意:這里不同于ab,后者會(huì)在給定時(shí)間后停止接收請(qǐng)求。

-k or --keepalive
Open connections using keep-alive: use header "Connection: Keep-alive" instead of "Connection: Close".

使用keepalive打開連接,使用請(qǐng)求頭 "Connection: Keep-alive" instead of "Connection: Close".

Note: Uses agentkeepalive,
which performs better than the default node.js agent.

注意:使用agentkeepalive會(huì)好過(guò)默認(rèn)的node.js代理。

-C cookie-name=value
Send a cookie with the request. The cookie name=value is then sent to the server.
This parameter can be repeated as many times as needed.

發(fā)送請(qǐng)求cookie,name=value會(huì)被發(fā)送到服務(wù)端。
這個(gè)參數(shù)能夠根據(jù)需要重復(fù)使用。

-H header:value
Send a custom header with the request. The line header:value is then sent to the server.
This parameter can be repeated as many times as needed.

發(fā)送自定義請(qǐng)求頭的請(qǐng)求,這行的header:value會(huì)被發(fā)送到服務(wù)端。
這個(gè)參數(shù)能夠重復(fù)多次使用。

Example:

$ loadtest -H user-agent:tester/0.4 ...
Note: if not present, loadtest will add a few headers on its own: the "host" header parsed from the URL,
a custom user agent "loadtest/" plus version (loadtest/1.1.0), and an accept header for "*/*".

注意:如果不存在,loadtest會(huì)附加一些自己的頭信息。從URL解析出來(lái)的“host”頭,一個(gè)自定義的用戶代理"loadtest/"附加版本(loadtest/1.1.0),可接受"*/*"頭。

Note: when the same header is sent several times, only the last value will be considered.
If you want to send multiple values with a header, separate them with semicolons:

注意:當(dāng)同一個(gè)請(qǐng)求頭發(fā)送給服務(wù)端幾次,只有最后的值會(huì)被考慮。
如果你想一個(gè)請(qǐng)求頭發(fā)送多個(gè)值,使用分號(hào)分割。

$ loadtest -H accept:text/plain;text-html ...
Note: if you need to add a header with spaces, be sure to surround both header and value with quotes:

注意:如果你需要添加空格頭,確保引號(hào)包裹著頭和值兩端;

$ loadtest -H "Authorization: Basic xxx=="
-T content-type
Set the MIME content type for POST data. Default: text/plain.

設(shè)置POST提交數(shù)據(jù)的MIME內(nèi)容類型,默認(rèn): text/plain.

-P POST-body
Send the string as the POST body. E.g.: -P "{"key": "a9acf03f"}"

發(fā)送一段字符串作為POST請(qǐng)求體,例如: -P "{"key": "a9acf03f"}"

-A PATCH-body
Send the string as the PATCH body. E.g.: -A "{"key": "a9acf03f"}"

發(fā)送一段字符串作為PATCH請(qǐng)求體,例如: -A "{"key": "a9acf03f"}"

-m method
Send method to link. Accept: [GET, POST, PUT, DELETE, PATCH, get, post, put, delete, patch], Default is GET,E.g.: -m POST

發(fā)送到鏈接的方法。可接受[GET, POST, PUT, DELETE, PATCH, get, post, put, delete, patch],默認(rèn)是GET,例如:-m POST

--data POST some variables
Send some data. It does not support method GET. E.g: --data "{"username": "test", "password": "test"}" -T "application/x-www-form-urlencoded" -m POST

It required -m and -T "application/x-www-form-urlencoded"

發(fā)送一些數(shù)據(jù),不支持方法GET
E.g: --data "{"username": "test", "password": "test"}" -T "application/x-www-form-urlencoded" -m POST

它需要-m and -T "application/x-www-form-urlencoded"

-p POST-file
Send the data contained in the given file in the POST body.
Remember to set -T to the correct content-type.

發(fā)送被包含在給定文件的POST請(qǐng)求體的數(shù)據(jù)。
記住設(shè)置給-T 正確的內(nèi)容類型。

If POST-file has .js extension it will be required. It should be a valid node module and it
should export a single function, which is invoked with an automatically generated request identifier
to provide the body of each request.
This is useful if you want to generate request bodies dynamically and vary them for each request.

如果 POST-file.js擴(kuò)展名會(huì)被引入,它應(yīng)該是一個(gè)有效的Node模塊并且導(dǎo)出單個(gè)使用自動(dòng)生成的請(qǐng)求標(biāo)識(shí)符調(diào)用提供每個(gè)請(qǐng)求的主體的函數(shù)。如果你想要?jiǎng)討B(tài)生成請(qǐng)求并且改變它們的每一個(gè)這非常有用。
(有點(diǎn)拗口,不知道翻譯對(duì)不對(duì))

Example:

module.exports = function(requestId) {
  // this object will be serialized to JSON and sent in the body of the request
  return {
    key: "value",
    requestId: requestId
  };
};
-u PUT-file
Send the data contained in the given file as a PUT request.
Remember to set -T to the correct content-type.

發(fā)送被包含在給定文件的PUT請(qǐng)求體的數(shù)據(jù)。
記住設(shè)置給-T 正確的內(nèi)容類型。

If PUT-file has .js extension it will be required. It should be a valid node module and it
should export a single function, which is invoked with an automatically generated request identifier
to provide the body of each request.
This is useful if you want to generate request bodies dynamically and vary them for each request.
For an example function see above for -p.

如果 PUT-file.js擴(kuò)展名會(huì)被引入,它應(yīng)該是一個(gè)有效的Node模塊并且導(dǎo)出單個(gè)使用自動(dòng)生成的請(qǐng)求標(biāo)識(shí)符調(diào)用提供每個(gè)請(qǐng)求的主體的函數(shù)。如果你想要?jiǎng)討B(tài)生成請(qǐng)求并且改變它們的每一個(gè)這非常有用。
示例函數(shù)請(qǐng)參見上面的 -p

-a PATCH-file
Send the data contained in the given file as a PATCH request.
Remember to set -T to the correct content-type.

發(fā)送被包含在給定文件的PATCH請(qǐng)求體的數(shù)據(jù)。
記住設(shè)置給-T 正確的內(nèi)容類型。

If PATCH-file has .js extension it will be required. It should be a valid node module and it
should export a single function, which is invoked with an automatically generated request identifier
to provide the body of each request.
This is useful if you want to generate request bodies dynamically and vary them for each request.
For an example function see above for -p.

如果 PATCH-file.js擴(kuò)展名會(huì)被引入,它應(yīng)該是一個(gè)有效的Node模塊并且導(dǎo)出單個(gè)使用自動(dòng)生成的請(qǐng)求標(biāo)識(shí)符調(diào)用提供每個(gè)請(qǐng)求的主體的函數(shù)。如果你想要?jiǎng)討B(tài)生成請(qǐng)求并且改變它們的每一個(gè)這非常有用。
示例函數(shù)請(qǐng)參見上面的 -p

-r
Recover from errors. Always active: loadtest does not stop on errors.
After the tests are finished, if there were errors a report with all error codes will be shown.

從錯(cuò)誤中恢復(fù),總是處于活躍之中:loadtest不會(huì)因?yàn)殄e(cuò)誤而停止。
在測(cè)試完成之后,如果出現(xiàn)錯(cuò)誤,將顯示一個(gè)包含所有錯(cuò)誤碼的報(bào)告。

-s
The TLS/SSL method to use. (e.g. TLSv1_method)

使用TLS/SSL方法,(例如TLSv1_method)

Example:

?

$ loadtest -n 1000 -s TLSv1_method https://www.example.com
-V
Show version number and exit.

顯示版本號(hào)并且退出

Advanced Usage
The following parameters are not compatible with Apache ab.

下面參數(shù)并不兼容Apache ab.

--rps requestsPerSecond
Controls the number of requests per second that are sent.
Can be fractional, e.g. --rps 0.5 sends one request every two seconds.

控制每秒發(fā)送請(qǐng)求的數(shù)量。
可以是小數(shù),例如--rps 0.5 兩秒發(fā)送一個(gè)請(qǐng)求。

Note: Concurrency doesn"t affect the final number of requests per second,
since rps will be shared by all the clients. E.g.:

注意:并發(fā)性不影響最終每秒發(fā)送的請(qǐng)求數(shù),
因?yàn)閞ps會(huì)被所有客戶端共享,例如

loadtest  -c 10 --rps 10
will send a total of 10 rps to the given URL, from 10 different clients
(each client will send 1 request per second).

會(huì)從10個(gè)不同的客戶端向給定的URL發(fā)送總共10rps(每個(gè)客戶端將每秒發(fā)送一個(gè)請(qǐng)求)

Beware: if concurrency is too low then it is possible that there will not be enough clients
to send all of the rps, adjust it with -c if needed.

注意:如果并發(fā)太低可能會(huì)導(dǎo)致沒有足夠的客戶端發(fā)送所有的rps,需要的話可以使用-c調(diào)整。

Note: --rps is not supported for websockets.

注意:--rps不支持websockets

--timeout milliseconds
Timeout for each generated request in milliseconds.
Setting this to 0 disables timeout (default).

每個(gè)生成請(qǐng)求的超時(shí)時(shí)間為毫秒
設(shè)置為0禁止超時(shí)(默認(rèn))

-R requestGeneratorModule.js
Use custom request generator function from an external file.

使用外部文件的自定義請(qǐng)求生成函數(shù)

Example request generator module could look like this:

外部文件的自定義請(qǐng)求生成函數(shù)可能如下:

module.exports = function(params, options, client, callback) {
  generateMessageAsync(function(message) {

    if (message)
    {
      options.headers["Content-Length"] = message.length;
      options.headers["Content-Type"] = "application/x-www-form-urlencoded";
    }
    request = client(options, callback);
    if (message){
      request.write(message);
    }

    return request;
  }
}
See sample/request-generator.js
for some sample code including a body.

查看sample/request-generator.js一些包括主體的示例代碼

--agent (deprecated)
Open connections using keep-alive.

使用長(zhǎng)連接打開

Note: instead of using the default agent, this option is now an alias for -k.

注意:這個(gè)選項(xiàng)不是使用默認(rèn)代理,而是-k的別名。

--quiet
Do not show any messages.

不展示任何信息

--debug
Show debug messages.

展示debug信息

--insecure
Allow invalid and self-signed certificates over https.

允許無(wú)效和自簽名證書通過(guò)https。

--cert path/to/cert.pem
Sets the certificate for the http client to use. Must be used with --key.

設(shè)置http客戶端使用的證書,必須使用--key.

--key path/to/key.pem
Sets the key for the http client to use. Must be used with --cert.

設(shè)置http客戶端使用的key,必須使用--cert.

Server
loadtest bundles a test server. To run it:

loadtest捆綁一個(gè)測(cè)試服務(wù)器,運(yùn)行:

$ testserver-loadtest [--delay ms] [error 5xx] [percent yy] [port]
This command will show the number of requests received per second,
the latency in answering requests and the headers for selected requests.

這個(gè)命令將顯示每秒接收的請(qǐng)求數(shù),響應(yīng)請(qǐng)求延遲和所選請(qǐng)求頭。

The server returns a short text "OK" for every request,
so that latency measurements don"t have to take into account request processing.

服務(wù)器會(huì)為每個(gè)請(qǐng)求返回短文OK
所以延遲測(cè)量不需要考慮處理請(qǐng)求。

If no port is given then default port 7357 will be used.
The optional delay instructs the server to wait for the given number of milliseconds
before answering each request, to simulate a busy server.
You can also simulate errors on a given percent of requests.

如果沒有給定端口會(huì)默認(rèn)使用7357.
延遲可選項(xiàng)命令服務(wù)器在每個(gè)請(qǐng)求響應(yīng)之前等待給定的毫秒數(shù)模擬繁忙的服務(wù)器。你可以在給定的請(qǐng)求百分比中模擬錯(cuò)誤。

Complete Example
Let us now see how to measure the performance of the test server.

讓我們看看怎么測(cè)量測(cè)試服務(wù)器的性能

First we install loadtest globally:

首先全局安裝loadtest

$ sudo npm install -g loadtest
Now we start the test server:

現(xiàn)在我們開啟測(cè)試服務(wù)器

$ testserver-loadtest
Listening on port 7357
On a different console window we run a load test against it for 20 seconds
with concurrency 10 (only relevant results are shown):

在不同的控制臺(tái)窗口我們靠它運(yùn)行負(fù)載測(cè)試在20秒內(nèi)并發(fā)量10(只有相關(guān)結(jié)果會(huì)展示)

$ loadtest http://localhost:7357/ -t 20 -c 10
...
Requests: 9589, requests per second: 1915, mean latency: 10 ms
Requests: 16375, requests per second: 1359, mean latency: 10 ms
Requests: 16375, requests per second: 0, mean latency: 0 ms
...
Completed requests:  16376
Requests per second: 368
Total time:          44.503181166000005 s

Percentage of the requests served within a certain time
  50%      4 ms
  90%      5 ms
  95%      6 ms
  99%      14 ms
 100%      35997 ms (longest request)
Results were quite erratic, with some requests taking up to 36 seconds;
this suggests that Node.js is queueing some requests for a long time, and answering them irregularly.
Now we will try a fixed rate of 1000 rps:

結(jié)果相當(dāng)不穩(wěn)定,有些請(qǐng)求占用了36秒;
這暗示Nodejs很長(zhǎng)一段時(shí)間內(nèi)都在排列一些請(qǐng)求然后不定期響應(yīng)它們。
現(xiàn)在我們嘗試1000rps的固定速率。

$ loadtest http://localhost:7357/ -t 20 -c 10 --rps 1000
...
Requests: 4551, requests per second: 910, mean latency: 0 ms
Requests: 9546, requests per second: 1000, mean latency: 0 ms
Requests: 14549, requests per second: 1000, mean latency: 20 ms
...
Percentage of the requests served within a certain time
  50%      1 ms
  90%      2 ms
  95%      8 ms
  99%      133 ms
 100%      1246 ms (longest request)
Again erratic results. In fact if we leave the test running for 50 seconds we start seeing errors:

再次不穩(wěn)定,事實(shí)上如果我們讓測(cè)試運(yùn)行50秒,我們就會(huì)看到錯(cuò)誤。

$ loadtest http://localhost:7357/ -t 50 -c 10 --rps 1000
...
Requests: 29212, requests per second: 496, mean latency: 14500 ms
Errors: 426, accumulated errors: 428, 1.5% of total requests
Let us lower the rate to 500 rps:

讓我們低于500rps運(yùn)行看看

$ loadtest http://localhost:7357/ -t 20 -c 10 --rps 500
...
Requests: 0, requests per second: 0, mean latency: 0 ms
Requests: 2258, requests per second: 452, mean latency: 0 ms
Requests: 4757, requests per second: 500, mean latency: 0 ms
Requests: 7258, requests per second: 500, mean latency: 0 ms
Requests: 9757, requests per second: 500, mean latency: 0 ms
...
Requests per second: 500
Completed requests:  9758
Total errors:        0
Total time:          20.002735398000002 s
Requests per second: 488
Total time:          20.002735398000002 s

Percentage of the requests served within a certain time
  50%      1 ms
  90%      1 ms
  95%      1 ms
  99%      14 ms
 100%      148 ms (longest request)
Much better: a sustained rate of 500 rps is seen most of the time,
488 rps average, and 99% of requests answered within 14 ms.

好很多了:能看到大多數(shù)時(shí)間都持續(xù)在500rps速率,平均488rps和99%請(qǐng)求響應(yīng)在14毫秒內(nèi)。

We now know that our server can accept 500 rps without problems.
Not bad for a single-process na?ve Node.js server...
We may refine our results further to find at which point from 500 to 1000 rps our server breaks down.

我們現(xiàn)在知道我們的服務(wù)器在500rps內(nèi)沒有問(wèn)題。
對(duì)一個(gè)單進(jìn)程純Node.js服務(wù)器來(lái)說(shuō)不差。。。
我們可以進(jìn)一步改進(jìn)我們的結(jié)果,以發(fā)現(xiàn)我們的服務(wù)器從500到1000 rps在哪個(gè)點(diǎn)崩潰。

But instead let us research how to improve the results.
One obvious candidate is to add keep-alive to the requests so we don"t have to create
a new connection for every request.
The results (with the same test server) are impressive:

但是,讓我們研究一下如何改進(jìn)結(jié)果。
一個(gè)明顯的后備方案是添加長(zhǎng)連接請(qǐng)求讓我們不需要為每個(gè)請(qǐng)求創(chuàng)建新的連接。
結(jié)果(同一個(gè)測(cè)試服務(wù)器)感人。

$ loadtest http://localhost:7357/ -t 20 -c 10 -k
...
Requests per second: 4099

Percentage of the requests served within a certain time
50%      2 ms
90%      3 ms
95%      3 ms
99%      10 ms
100%      25 ms (longest request)
Now you"re talking! The steady rate also goes up to 2 krps:

現(xiàn)在你們可以說(shuō),這穩(wěn)定比率總是達(dá)到2rps;

$ loadtest http://localhost:7357/ -t 20 -c 10 --keepalive --rps 2000
...
Requests per second: 1950

Percentage of the requests served within a certain time
  50%      1 ms
  90%      2 ms
  95%      2 ms
  99%      7 ms
 100%      20 ms (longest request)
Not bad at all: 2 krps with a single core, sustained.
However, it you try to push it beyond that, at 3 krps it will fail miserably.

一點(diǎn)也不差:?jiǎn)魏?krps,穩(wěn)定。
然而,如果你試圖推上3krps會(huì)失敗地很慘。

API
loadtest is not limited to running from the command line; it can be controlled using an API,
thus allowing you to load test your application in your own tests.

loadtest不限于從命令行運(yùn)行;它能夠使用API控制,因此允許你在自己的測(cè)試?yán)锶ヘ?fù)載測(cè)試你的應(yīng)用程序。

執(zhí)行負(fù)載測(cè)試
To run a load test, just call the exported function loadTest() with a set of options and an optional callback:

運(yùn)行負(fù)載測(cè)試,只要設(shè)置一些可選項(xiàng)和可選回調(diào)函數(shù)調(diào)用導(dǎo)出函數(shù)loadTest()

const loadtest = require("loadtest");
const options = {
    url: "http://localhost:8000",
    maxRequests: 1000,
};
loadtest.loadTest(options, function(error, result)
{
    if (error)
    {
        return console.error("Got an error: %s", error);
    }
    console.log("Tests run successfully");
});
The callback function(error, result) will be invoked when the max number of requests is reached,or when the max number of seconds has elapsed.

當(dāng)最大請(qǐng)求數(shù)已經(jīng)達(dá)到或者當(dāng)秒數(shù)超過(guò)最大值之后回調(diào)函數(shù) function(error, result) 會(huì)被執(zhí)行。

Beware: if there are no maxRequests and no maxSeconds, then tests will run forever and will not call the callback.

注意:如果沒有maxRequestsmaxSeconds,測(cè)試會(huì)一直運(yùn)行不執(zhí)行回調(diào)。

Options
All options but url are, as their name implies, optional.

除了url以外所有可選項(xiàng),顧名思義都是可選

url
The URL to invoke. Mandatory.

要調(diào)用的URL,必須

concurrency
How many clients to start in parallel.

客戶端并行啟動(dòng)數(shù)量。

maxRequests
A max number of requests; after they are reached the test will end.

請(qǐng)求最大量;當(dāng)達(dá)到之后測(cè)試會(huì)結(jié)束

Note: the actual number of requests sent can be bigger if there is a concurrency level;
loadtest will report just on the max number of requests.

注意:如果是并發(fā)級(jí)別實(shí)際發(fā)送請(qǐng)求數(shù)量更加大;loadtest只會(huì)報(bào)出請(qǐng)求最大量。

maxSeconds
Max number of seconds to run the tests.

運(yùn)行測(cè)試的最大秒數(shù)。

Note: after the given number of seconds loadtest will stop sending requests,
but may continue receiving tests afterwards.

注意:loadtest會(huì)在給定的秒數(shù)之后停止發(fā)送請(qǐng)求,但之后可能會(huì)繼續(xù)接受測(cè)試。

timeout
Timeout for each generated request in milliseconds. Setting this to 0 disables timeout (default).

每個(gè)生成請(qǐng)求的超時(shí)時(shí)間,0為禁止超時(shí)(默認(rèn))。

cookies
An array of cookies to send. Each cookie should be a string of the form name=value.

發(fā)送一組cookies,每個(gè)cookie應(yīng)該是表單名稱=值的字符串。

headers
A map of headers. Each header should be an entry in the map with the value given as a string.
If you want to have several values for a header, write a single value separated by semicolons,
like this:

請(qǐng)求頭映射,每個(gè)請(qǐng)求頭應(yīng)該是映射的一個(gè)條目,其值是字符串輸出。如果你想要有一個(gè)條目多個(gè)值,使用分號(hào)切割:

{
    accept: "text/plain;text/html"
}
Note: when using the API, the "host" header is not inferred from the URL but needs to be sent explicitly.

注意:當(dāng)使用API,"host"不會(huì)從URL推導(dǎo)出來(lái),需要明確傳輸過(guò)來(lái)。

method
The method to use: POST, PUT. Default: GET.

使用方法POST, PUT,默認(rèn)GET。

body
The contents to send in the body of the message, for POST or PUT requests.
Can be a string or an object (which will be converted to JSON).

在消息體中發(fā)送的內(nèi)容,用于POST或PUT請(qǐng)求。可以是字符串或者對(duì)象(需要轉(zhuǎn)譯成JSON)

contentType
The MIME type to use for the body. Default content type is text/plain.

請(qǐng)求體使用的MIME類型,默認(rèn)text/plain.

requestsPerSecond
How many requests each client will send per second.

每個(gè)客戶端每秒發(fā)送多少請(qǐng)求

requestGenerator
Custom request generator function.

自定義請(qǐng)求生成函數(shù)。

Example request generator function could look like this:

自定義請(qǐng)求生成器函數(shù)可能如下:

function(params, options, client, callback) {
  generateMessageAsync(function(message)) {
    request = client(options, callback);

    if (message)
    {
      options.headers["Content-Length"] = message.length;
      options.headers["Content-Type"] = "application/x-www-form-urlencoded";
      request.write(message);
    }

    request.end();
  }
}
agentKeepAlive
Use an agent with "Connection: Keep-alive".

使用Connection: Keep-alive代理

Note: Uses agentkeepalive,
which performs better than the default node.js agent.

注意:使用agentkeepalive性能更加優(yōu)異于默認(rèn)nodejs代理。

quiet
Do not show any messages.

不顯示任何信息

indexParam
The given string will be replaced in the final URL with a unique index.
E.g.: if URL is http://test.com/value and indexParam=value, then the URL
will be:

給定字符串會(huì)在最終URL替換為唯一索引。
例如:如果URL是 http://test.com/valueindexParam=value,之后URl會(huì)是

http://test.com/1

http://test.com/2

...

body will also be replaced body:{ userid: id_value } will be body:{ userid: id_1 }

insecure
Allow invalid and self-signed certificates over https.

允許無(wú)效和自簽名證書通過(guò)https。

secureProtocol
The TLS/SSL method to use. (e.g. TLSv1_method)

使用TLS/SSL方法,(例如TLSv1_method)

Example:

const loadtest = require("loadtest");

const options = {
    url: "https://www.example.com",
    maxRequests: 100,
    secureProtocol: "TLSv1_method"
};

loadtest.loadTest(options, function(error) {
    if (error) {
        return console.error("Got an error: %s", error);
    }
    console.log("Tests run successfully");
});
statusCallback
Execution this function after every request operation completes. Provides immediate access to test results while the
test batch is still running. This can be used for more detailed custom logging or developing your own spreadsheet or
statistical analysis of results.

每次請(qǐng)求操作完成后執(zhí)行此函數(shù)。測(cè)試批處理仍在運(yùn)行時(shí)提供對(duì)測(cè)試結(jié)果的即時(shí)訪問(wèn)。這可以用于更詳細(xì)的自定義日志記錄或開發(fā)您自己的電子表格或
統(tǒng)計(jì)分析的結(jié)果。

The results and error passed to the callback are in the same format as the results passed to the final callback.

傳遞給回調(diào)的結(jié)果和錯(cuò)誤的格式與傳遞給最終回調(diào)的結(jié)果相同。

In addition, the following three properties are added to the result object:

需要注意的是,下面三個(gè)屬性值被添加到result對(duì)象:

requestElapsed: time in milliseconds it took to complete this individual request.

requestIndex: 0-based index of this particular request in the sequence of all requests to be made.

instanceIndex: the loadtest(...) instance index. This is useful if you call loadtest() more than once.

requestElapsed: 完成這個(gè)多帶帶的請(qǐng)求所需的時(shí)間(毫秒).

requestIndex: 基于0開始的隊(duì)列中所有請(qǐng)求的順序中的索引值。

instanceIndex: loadtest(...)實(shí)例的索引值,如果你多次調(diào)用loadtest()的話這非常有用。

You will need to check if error is populated in order to determine which object to check for these properties.

您需要檢查是否填充了“error”,以確定要哪些對(duì)象來(lái)檢查這些屬性。
(怪怪的,不知道怎么翻)

Example:

const loadtest = require("loadtest");

function statusCallback(error, result, latency) {
    console.log("Current latency %j, result %j, error %j", latency, result, error);
    console.log("----");
    console.log("Request elapsed milliseconds: ", result.requestElapsed);
    console.log("Request index: ", result.requestIndex);
    console.log("Request loadtest() instance index: ", result.instanceIndex);
}

const options = {
    url: "http://localhost:8000",
    maxRequests: 1000,
    statusCallback: statusCallback
};

loadtest.loadTest(options, function(error) {
    if (error) {
        return console.error("Got an error: %s", error);
    }
    console.log("Tests run successfully");
});
Warning: The format for statusCallback has changed in version 2.0.0 onwards.
It used to be statusCallback(latency, result, error),
it has been changed to conform to the usual Node.js standard.

警告: statusCallback 格式在2.0.0版本已經(jīng)改變。
它曾經(jīng)用 statusCallback(latency, result, error)
它已經(jīng)更改為符合Nodejs常用標(biāo)準(zhǔn)

Results
The latency results passed to your callback at the end of the load test contains a full set of data, including: mean latency, number of errors and percentiles.

延遲結(jié)果會(huì)在負(fù)載測(cè)試結(jié)束時(shí)傳遞給你的回調(diào)函數(shù)包含完整的數(shù)據(jù),包括:平均延遲,錯(cuò)誤數(shù)量和百分比.

An example follows:

{
  totalRequests: 1000,
  percentiles: {
    "50": 7,
    "90": 10,
    "95": 11,
    "99": 15
  },
  rps: 2824,
  totalTimeSeconds: 0.354108,
  meanLatencyMs: 7.72,
  maxLatencyMs: 20,
  totalErrors: 3,
  errors: {
    "0": 1,
    "500": 2
  }
}
The second parameter contains info about the current request:

第二個(gè)參數(shù)包含當(dāng)前請(qǐng)求信息

{
    host: "localhost",
    path: "/",
    method: "GET",
    statusCode: 200,
    body: "hi",
    headers: [...]
}
Start Test Server
To start the test server use the exported function startServer() with a set of options and an optional callback:

使用導(dǎo)出函數(shù)startServer() 開始測(cè)試服務(wù)器,包含一組選項(xiàng)和一個(gè)可選回調(diào);

const testserver = require("testserver");
const server = testserver.startServer({ port: 8000 });
This function returns an HTTP server which can be close()d when it is no longer useful.

函數(shù)返回一個(gè)HTTP服務(wù)器當(dāng)它不再需要的時(shí)候能夠使用 close()關(guān)閉

The following options are available.

下面可配置項(xiàng)。

port
Optional port to use for the server.

可選端口

Note: the default port is 7357, since port 80 requires special privileges.

注意默認(rèn)端口為7357,因?yàn)?0需要特權(quán)

delay
Wait the given number of milliseconds to answer each request.

每個(gè)請(qǐng)求響應(yīng)前需要等待多久

error
Return an HTTP error code.

返回HTTP錯(cuò)誤碼

percent
Return an HTTP error code only for the given % of requests.
If no error code was specified, default is 500.

只有給定百分比數(shù)量的請(qǐng)求會(huì)返回一個(gè)HTTP錯(cuò)誤碼。
如果沒有指定錯(cuò)誤碼默認(rèn)500

Complete Example
The file lib/integration.js shows a complete example, which is also a full integration test:
it starts the server, send 1000 requests, waits for the callback and closes down the server.

lib/integration.js文件展示完整樣例,是一個(gè)完整的集成測(cè)試;
啟動(dòng)服務(wù)器會(huì)發(fā)送1000個(gè)請(qǐng)求等待回調(diào)函數(shù)然后關(guān)閉服務(wù)器。

Versioning
Version 3.x uses ES2015 (ES6) features,
such as const or let and arrow functions.
For ES5 support please use versions 2.x.

3.x版本能使用ES6特性,例如 const 或者 let和箭頭函數(shù)。
2.x版本支持ES5.

Licensed under The MIT License

Copyright (c) 2013-4 Alex Fernández
and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

特此授予許可,任何人免費(fèi)獲得這個(gè)軟件和相關(guān)的文檔文件的副本(“軟件”),在軟件處理無(wú)限制,包括但不限于使用、復(fù)制、修改、合并、出版、發(fā)行、有償、和/或銷售的軟件副本權(quán)利,并允許他們軟件供應(yīng),應(yīng)當(dāng)具備下列條件:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

上述版權(quán)通知和本許可通知應(yīng)包含在本軟件的所有副本或大部分內(nèi)容中。

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

本軟件是“按原樣”提供的,沒有任何明示或暗示的保證,包括但不限于適銷性、特定用途的適用性和不侵權(quán)的保證。在任何情況下,作者或版權(quán)持有人均不應(yīng)對(duì)任何索賠、損害或其他責(zé)任承擔(dān)責(zé)任,無(wú)論是在合同、侵權(quán)或其他行為中,由本軟件引起、由本軟件引起或與本軟件的使用或其他有關(guān)交易。

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/106352.html

相關(guān)文章

  • 】確保網(wǎng)站性能的5個(gè)小貼士

    摘要:定期進(jìn)行負(fù)載測(cè)試負(fù)載測(cè)試顯示您的網(wǎng)站在一定數(shù)量的用戶訪問(wèn)時(shí)的表現(xiàn)。如果負(fù)載測(cè)試顯示的頁(yè)面加載時(shí)間比預(yù)期的要長(zhǎng),那么網(wǎng)站設(shè)計(jì)的小改動(dòng)就能帶來(lái)所需的改進(jìn)。 確保網(wǎng)站性能的5個(gè)小貼士 翻譯:瘋狂的技術(shù)宅作者:Jennifer Oksnevad英文標(biāo)題:5 Tips to ensure website performance英文原文:https://www.catswhocode.com/b....

    ls0609 評(píng)論0 收藏0
  • 】確保網(wǎng)站性能的5個(gè)小貼士

    摘要:定期進(jìn)行負(fù)載測(cè)試負(fù)載測(cè)試顯示您的網(wǎng)站在一定數(shù)量的用戶訪問(wèn)時(shí)的表現(xiàn)。如果負(fù)載測(cè)試顯示的頁(yè)面加載時(shí)間比預(yù)期的要長(zhǎng),那么網(wǎng)站設(shè)計(jì)的小改動(dòng)就能帶來(lái)所需的改進(jìn)。 確保網(wǎng)站性能的5個(gè)小貼士 翻譯:瘋狂的技術(shù)宅作者:Jennifer Oksnevad英文標(biāo)題:5 Tips to ensure website performance英文原文:https://www.catswhocode.com/b....

    singerye 評(píng)論0 收藏0
  • [] 設(shè)計(jì)一個(gè)容錯(cuò)的微服務(wù)架構(gòu)

    摘要:微服務(wù)架構(gòu)的風(fēng)險(xiǎn)微服務(wù)架構(gòu)將應(yīng)用程序邏輯移動(dòng)到服務(wù),并使用網(wǎng)絡(luò)層在它們之間進(jìn)行通信。在微服務(wù)架構(gòu)中,服務(wù)依賴于彼此。您始終只能部署其中一個(gè),并且在驗(yàn)證新版本是否符合預(yù)期之后才,將負(fù)載均衡器指向新的。 [譯] 設(shè)計(jì)一個(gè)容錯(cuò)的微服務(wù)架構(gòu) 摘要:本文屬于原創(chuàng),歡迎轉(zhuǎn)載,轉(zhuǎn)載請(qǐng)保留出處:https://github.com/jasonGeng88/blog 原文地址 https://blog....

    raledong 評(píng)論0 收藏0
  • 推薦輕量高效無(wú)依賴的開源JS插件和庫(kù)

    摘要:彈出層是一個(gè)輕量級(jí)的庫(kù)用于管理工具提示和彈窗效果。一個(gè)帶有的跨瀏覽器富文本編輯器。由制作,適用于每天寫作的富文本編輯器。輕量的操作庫(kù)。是一個(gè)快速簡(jiǎn)單輕量級(jí)的瀏覽器功能檢測(cè)庫(kù)。它沒有任何的依賴,并且壓縮后僅有。極小跨平臺(tái)的全屏插件。 在這里維持一個(gè)持續(xù)更新的地方 圖片 baguetteBox.js - 是一個(gè)簡(jiǎn)單易用的響應(yīng)式圖像燈箱效果腳本。demo Lightgallery.js -...

    AlphaWallet 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<