亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

[譯]Loadtest庫做負載測試

asoren / 2002人閱讀

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

前言

因為最近學(xué)習(xí)需要用到一些測試庫測試性能,但是工具又太復(fù)雜不好用,恰好發(fā)現(xiàn)有這么一個庫用法輸出都很近似,可惜沒有找到有中文版或者用法筆記,所以只好耐心一點一點翻譯出來。因為我的英文水平很一般,而這種技術(shù)博客直接機翻是表達不出意思的,只能硬著頭皮按自己理解寫出來,為了不誤人誤己,我在原文底下翻譯,這樣大家也可以直接看原文。
全文加起來一萬八字,原文大概就九千字吧,如果嫌界面排版難看的直接去原文吧。
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上進行負載測試,API允許在你自己的測試?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:

想要訪問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)整請求去模擬真實世界的負載。

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

作為腳本執(zhí)行去負載測試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è)置最大請求數(shù),
-c設(shè)置并發(fā)級別,
除了測試打開和關(guān)閉連接以外有意義的時候可以用-k做長連接。

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.

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

To get online help, run loadtest without parameters:

想要獲取線上幫助,運行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è)置選項被設(shè)計為可兼容Apache ab,然而ab只能設(shè)置并發(fā)級別讓服務(wù)端調(diào)整它。loadtest允許你用--rps選項設(shè)置每秒速率或請求數(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.

這個命令在10并發(fā)量情況下每秒發(fā)送200個請求,所以你能看到你的服務(wù)端怎么處理持續(xù)的rps。即使是ab報告的速率是200rps,你也會驚奇地看到每秒請求的恒定速率怎么影響性能;不再調(diào)整請求到服務(wù)器,但是服務(wù)器必須調(diào)整到請求! Rps率通常會大幅降低至少20~25%(在我們的例子200-150rps),但由此得出的數(shù)據(jù)要穩(wě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是可擴展的。使用提供的API非常容易整合loadtest到你的包里進行編程負載測試。在部署新版本軟件之前,loadtest使運行負載測試成為系統(tǒng)測試的一部分變得非常容易。
結(jié)果包括平均響應(yīng)時間和百分比,以便你可以終止部署,例如,如果99%的請求在10毫秒或更短的時間內(nèi)沒有完成。

注意事項
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會很快使單個CPU飽和。
如果Node.js使用率已經(jīng)超過100%不要使用loadtest,當(dāng)你負載超過1000~4000rps會發(fā)生類似的事。
(你可以運行指定的測試機器測量loadtest的實際極限通過簡單的Apache 或者 nginx進程查看什么時候達到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)異,但是總是受限于單個CPU性能,它的實際極限大概40krps。

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

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

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

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

-n requests
Number of requests to send out.

發(fā)送請求數(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ā)送的請求總數(shù)可以大于參數(shù);loadtest將只報告第一個n。
(我猜這里意思是前一個n也就是發(fā)送的請求總數(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會創(chuàng)建一定數(shù)量的客戶端,這參數(shù)控制具體多少。
它們的請求會并發(fā)到達服務(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).

注意:請求實際上沒有并行發(fā)送(來自不同的進程),
但是并發(fā)(第二個請求在第一個請求響應(yīng)之前發(fā)送)

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

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

等待直到請求不再發(fā)送的時間

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

注意:這里不同于ab,后者會在給定時間后停止接收請求。

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

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

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

注意:使用agentkeepalive會好過默認的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ā)送請求cookie,name=value會被發(fā)送到服務(wù)端。
這個參數(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ā)送自定義請求頭的請求,這行的header:value會被發(fā)送到服務(wù)端。
這個參數(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會附加一些自己的頭信息。從URL解析出來的“host”頭,一個自定義的用戶代理"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)同一個請求頭發(fā)送給服務(wù)端幾次,只有最后的值會被考慮。
如果你想一個請求頭發(fā)送多個值,使用分號分割。

$ 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:

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

$ 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)容類型,默認: text/plain.

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

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

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

發(fā)送一段字符串作為PATCH請求體,例如: -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],默認是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請求體的數(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擴展名會被引入,它應(yīng)該是一個有效的Node模塊并且導(dǎo)出單個使用自動生成的請求標(biāo)識符調(diào)用提供每個請求的主體的函數(shù)。如果你想要動態(tài)生成請求并且改變它們的每一個這非常有用。
(有點拗口,不知道翻譯對不對)

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請求體的數(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擴展名會被引入,它應(yīng)該是一個有效的Node模塊并且導(dǎo)出單個使用自動生成的請求標(biāo)識符調(diào)用提供每個請求的主體的函數(shù)。如果你想要動態(tài)生成請求并且改變它們的每一個這非常有用。
示例函數(shù)請參見上面的 -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請求體的數(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擴展名會被引入,它應(yīng)該是一個有效的Node模塊并且導(dǎo)出單個使用自動生成的請求標(biāo)識符調(diào)用提供每個請求的主體的函數(shù)。如果你想要動態(tài)生成請求并且改變它們的每一個這非常有用。
示例函數(shù)請參見上面的 -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.

從錯誤中恢復(fù),總是處于活躍之中:loadtest不會因為錯誤而停止。
在測試完成之后,如果出現(xiàn)錯誤,將顯示一個包含所有錯誤碼的報告。

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

顯示版本號并且退出

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ā)送請求的數(shù)量。
可以是小數(shù),例如--rps 0.5 兩秒發(fā)送一個請求。

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ā)送的請求數(shù),
因為rps會被所有客戶端共享,例如

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

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

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ā)太低可能會導(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).

每個生成請求的超時時間為毫秒
設(shè)置為0禁止超時(默認)

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

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

Example request generator module could look like this:

外部文件的自定義請求生成函數(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.

使用長連接打開

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

注意:這個選項不是使用默認代理,而是-k的別名。

--quiet
Do not show any messages.

不展示任何信息

--debug
Show debug messages.

展示debug信息

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

允許無效和自簽名證書通過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捆綁一個測試服務(wù)器,運行:

$ 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.

這個命令將顯示每秒接收的請求數(shù),響應(yī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ù)器會為每個請求返回短文OK
所以延遲測量不需要考慮處理請求。

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.

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

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

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

First we install loadtest globally:

首先全局安裝loadtest

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

現(xiàn)在我們開啟測試服務(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):

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

$ 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)定,有些請求占用了36秒;
這暗示Nodejs很長一段時間內(nèi)都在排列一些請求然后不定期響應(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)定,事實上如果我們讓測試運行50秒,我們就會看到錯誤。

$ 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運行看看

$ 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ù)時間都持續(xù)在500rps速率,平均488rps和99%請求響應(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)沒有問題。
對一個單進程純Node.js服務(wù)器來說不差。。。
我們可以進一步改進我們的結(jié)果,以發(fā)現(xiàn)我們的服務(wù)器從500到1000 rps在哪個點崩潰。

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:

但是,讓我們研究一下如何改進結(jié)果。
一個明顯的后備方案是添加長連接請求讓我們不需要為每個請求創(chuàng)建新的連接。
結(jié)果(同一個測試服務(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)在你們可以說,這穩(wěn)定比率總是達到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.

一點也不差:單核2krps,穩(wěn)定。
然而,如果你試圖推上3krps會失敗地很慘。

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不限于從命令行運行;它能夠使用API控制,因此允許你在自己的測試?yán)锶ヘ撦d測試你的應(yīng)用程序。

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

運行負載測試,只要設(shè)置一些可選項和可選回調(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)最大請求數(shù)已經(jīng)達到或者當(dāng)秒數(shù)超過最大值之后回調(diào)函數(shù) function(error, result) 會被執(zhí)行。

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

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

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

除了url以外所有可選項,顧名思義都是可選

url
The URL to invoke. Mandatory.

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

concurrency
How many clients to start in parallel.

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

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

請求最大量;當(dāng)達到之后測試會結(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ā)級別實際發(fā)送請求數(shù)量更加大;loadtest只會報出請求最大量。

maxSeconds
Max number of seconds to run the tests.

運行測試的最大秒數(shù)。

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

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

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

每個生成請求的超時時間,0為禁止超時(默認)。

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

發(fā)送一組cookies,每個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:

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

{
    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"不會從URL推導(dǎo)出來,需要明確傳輸過來。

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

使用方法POST, PUT,默認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請求。可以是字符串或者對象(需要轉(zhuǎn)譯成JSON)

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

請求體使用的MIME類型,默認text/plain.

requestsPerSecond
How many requests each client will send per second.

每個客戶端每秒發(fā)送多少請求

requestGenerator
Custom request generator function.

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

Example request generator function could look like this:

自定義請求生成器函數(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)異于默認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:

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

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.

允許無效和自簽名證書通過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.

每次請求操作完成后執(zhí)行此函數(shù)。測試批處理仍在運行時提供對測試結(jié)果的即時訪問。這可以用于更詳細的自定義日志記錄或開發(fā)您自己的電子表格或
統(tǒng)計分析的結(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é)果和錯誤的格式與傳遞給最終回調(diào)的結(jié)果相同。

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

需要注意的是,下面三個屬性值被添加到result對象:

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: 完成這個多帶帶的請求所需的時間(毫秒).

requestIndex: 基于0開始的隊列中所有請求的順序中的索引值。

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

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

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

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é)果會在負載測試結(jié)束時傳遞給你的回調(diào)函數(shù)包含完整的數(shù)據(jù),包括:平均延遲,錯誤數(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:

第二個參數(shù)包含當(dā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() 開始測試服務(wù)器,包含一組選項和一個可選回調(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ù)返回一個HTTP服務(wù)器當(dāng)它不再需要的時候能夠使用 close()關(guān)閉

The following options are available.

下面可配置項。

port
Optional port to use for the server.

可選端口

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

注意默認端口為7357,因為80需要特權(quán)

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

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

error
Return an HTTP error code.

返回HTTP錯誤碼

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

只有給定百分比數(shù)量的請求會返回一個HTTP錯誤碼。
如果沒有指定錯誤碼默認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文件展示完整樣例,是一個完整的集成測試;
啟動服務(wù)器會發(fā)送1000個請求等待回調(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:

特此授予許可,任何人免費獲得這個軟件和相關(guān)的文檔文件的副本(“軟件”),在軟件處理無限制,包括但不限于使用、復(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)對任何索賠、損害或其他責(zé)任承擔(dān)責(zé)任,無論是在合同、侵權(quán)或其他行為中,由本軟件引起、由本軟件引起或與本軟件的使用或其他有關(guān)交易。

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

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/106352.html

相關(guān)文章

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

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

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

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

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

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

    raledong 評論0 收藏0
  • 推薦輕量高效無依賴的開源JS插件和庫

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

    AlphaWallet 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<