2 Star 0 Fork 0

小蚂蚁 / gurl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

gurl

Documentation

Build Status

简介

gurl 是http, websocket bench工具和curl的继承者

功能

  • 多协议支持http, websocket
  • 支持curl常用命令行选项
  • 支持压测模式,可以根据并发数和线程数,也可以根据持续时间,也可以指定每秒并发数压测http, websocket, tcp服务
  • url 支持简写
  • 支持管道模式

install

env GOPATH=`pwd` go get -u github.com/guonaihong/gurl/

gurl 主命令选项

http 子命令

guonaihong https://github.com/guonaihong/gurl

Usage of gurl:
  -A, --user-agent string
    	Send User-Agent STRING to server (default "gurl")
  -F, --form string[]
    	Specify HTTP multipart POST data (H) (default [])
  -H, --header string[]
    	Pass custom header LINE to server (H) (default [])
  -I, --input-model
    	open input mode
  -J string[]
    	Turn key:value into {"key": "value"})
  -Jfa string[]
    	Specify HTTP multipart POST json data (H)
  -Jfa-string string[]
    	Specify HTTP multipart POST json data (H)
  -O, --output-mode
    	open output mode
  -R, --input-read string
    	open input file
  -W, --output-write string
    	open output file
  -X, --request string
    	Specify request command to use
  -ac int
    	Number of multiple requests to make (default 1)
  -an int
    	Number of requests to perform (default 1)
  -bench
    	Run benchmarks test
  -c, --color
    	Color highlighting
  -connect-timeout string
    	Maximum time allowed for connection
  -conns int
    	Max open idle connections per target host (default 10000)
  -cpus int
    	Number of CPUs to use
  -d, --data string
    	HTTP POST data
  -debug
    	open debug mode
  -duration string
    	Duration of the test
  -form-string string[]
    	Specify HTTP multipart POST data (H) (default [])
  -input-fields string
    	sets the field separator (default " ")
  -l string
    	Listen mode, HTTP echo server
  -m, --merge
    	Combine the output results into the output
  -o, --output string
    	Write to FILE instead of stdout (default "stdout")
  -oflag string
    	Control the way you write(append|line|trunc)
  -q, --query string[]
    	query string
  -r, --read-stream
    	Read data from the stream
  -rate int
    	Requests per second
  -skey, --input-setkey string
    	Set a new name for the default key
  -url string
    	Specify a URL to fetch
  -v, --verbose
    	Make the operation more talkative
  -w, --write-stream
    	Write data from the stream
  -wkey, --write-key string
    	Key that can be write
-F 或 --form

设置form表单, 比如-F text=文本内容,或者-F text=@./从文件里面读取, -F 选项的语义和curl命令一样

--form-string

和-F 或--form类似,不解释@符号,原样传递到服务端

-ac

指定线程数, 开ac个线程, 发送an个请求

gurl http -an 10 -ac 2 -F text=good :1234
-an

指定次数

http 性能压测

-bench 压测模式,可以对http服务端进行压测,可以和-ac, -an, -duration, -rate 选项配合使用

   gurl http -bench -ac 25 -an 1000000 :1234
   Benchmarking 127.0.0.1 (be patient)
     Completed          100000 requests [2018-08-11 21:58:56.143]
     Completed          200000 requests [2018-08-11 21:59:00.374]
     Completed          300000 requests [2018-08-11 21:59:03.703]
     Completed          400000 requests [2018-08-11 21:59:06.559]
     Completed          500000 requests [2018-08-11 21:59:09.201]
     Completed          600000 requests [2018-08-11 21:59:11.757]
     Completed          700000 requests [2018-08-11 21:59:14.218]
     Completed          800000 requests [2018-08-11 21:59:16.639]
     Completed          900000 requests [2018-08-11 21:59:19.061]
     Completed         1000000 requests [2018-08-11 21:59:21.451]
     Finished          1000000 requests


   Server Software:        gurl-server
   Server Hostname:        
   Server Port:            1234

   Document Path:          
   Document Length:        0 bytes

   Status Codes:           200:1000000  [code:count]
   Concurrency Level:      10
   Time taken for tests:   28.807 seconds
   Complete requests:      1000000
   Failed requests:        0
   Total transferred:      137000000 bytes
   HTML transferred:       0 bytes
   Requests per second:    34713.37 [#/sec] (mean)
   Time per request:       0.288 [ms] (mean)
   Time per request:       0.029 [ms] (mean, across all concurrent requests)
   Transfer rate:          4755.73 [Kbytes/sec] received
   Percentage of the requests served within a certain time (ms)
     50%    0.21ms
     66%    0.31ms
     75%    0.38ms
     80%    0.42ms
     90%    0.57ms
     95%    0.66ms
     98%    0.79ms
     99%    0.89ms
    100%    16.45ms
-duration

和-bench选项一起使用,可以控制压测时间,支持单位符,ms(毫秒), s(秒), m(分), h(小时), d(天), w(周), M(月), y(年) 也可以混合使用 -duration 1m10s

-connect-timeout

设置http 连接超时时间。支持单位符,ms(毫秒), s(秒), m(分), h(小时), d(天), w(周), M(月), y(年)

-rate

指定每秒写多少条

gurl http -bench -ac 25 -an 3000 -rate 3000 :1234
Benchmarking 127.0.0.1 (be patient)
  Completed             300 requests [2018-08-11 22:02:01.625]
  Completed             600 requests [2018-08-11 22:02:01.725]
  Completed             900 requests [2018-08-11 22:02:01.825]
  Completed            1200 requests [2018-08-11 22:02:01.925]
  Completed            1500 requests [2018-08-11 22:02:02.025]
  Completed            1800 requests [2018-08-11 22:02:02.125]
  Completed            2100 requests [2018-08-11 22:02:02.225]
  Completed            2400 requests [2018-08-11 22:02:02.325]
  Completed            2700 requests [2018-08-11 22:02:02.425]
  Completed            3000 requests [2018-08-11 22:02:02.525]
  Finished             3000 requests


Server Software:        gurl-server
Server Hostname:        
Server Port:            1234

Document Path:          
Document Length:        0 bytes

Status Codes:           200:3000  [code:count]
Concurrency Level:      10
Time taken for tests:   1.000 seconds
Complete requests:      3000
Failed requests:        0
Total transferred:      411000 bytes
HTML transferred:       0 bytes
Requests per second:    3000.08 [#/sec] (mean)
Time per request:       3.333 [ms] (mean)
Time per request:       0.333 [ms] (mean, across all concurrent requests)
Transfer rate:          411.01 [Kbytes/sec] received
Percentage of the requests served within a certain time (ms)
  50%    0.17ms
  66%    0.18ms
  75%    0.18ms
  80%    0.19ms
  90%    0.21ms
  95%    0.23ms
  98%    0.26ms
  99%    0.31ms
 100%    1.34ms
-d 或 --data

发送http body数据到服务端, 支持@符号打开一个文件, 如果不接@直接把-d后面字符串发送到服务端

  gurl http -d "good" :12345
  gurl http -d "@./file" :12345
RESTful API

-J 拼装json字段到body里面 -J 后面的key和value 会被组装成json字符串发送到服务端. key:value,其中value会被解释成字符串, key:=value,value会被解决成bool或者数字或者小数

  • 普通用法
 ./gurl http -J username:admin passwd:123456 bool_val:=true  int_val:=3 float_val:=0.3 -url http://127.0.0.1:12345
 {
     "bool_val": true,
     "float_val": 0.3,
     "int_val": 3,
     "passwd": "123456",
     "username": "admin"
 }
  • 嵌套用法
./gurl http -J a.b.c.d:=true -J a.b.c.e:=111 http://127.0.0.1:12345
{
  "a": {
    "b": {
      "c": {
        "d:": true,
        "e:": 111
      }
    }
  }
}
查询字符串

-q 后跟查询字符串, key=val形式

gurl http -X POST -J hello:word startTime:123 endTime:456 -url :8080/test -vc -q appkey=hello world=hello
> POST /test?appkey=hello&world=hello HTTP/1.1
> Accept: */*
> Host: 127.0.0.1:8080
> User-Agent: gurl
>

< HTTP/1.1 200 OK
< Date: Tue, 21 May 2019 12:39:13 GMT
< Content-Length: 50
< Content-Type: text/plain; charset=utf-8


{
  "endTime": "456",
  "hello": "word",
  "startTime": "123"
}
-Jfa

向multipart字段中插入json数据

./gurl http -Jfa text=DisplayText:good text=Language:cn text2=look:me -F text=good :12345

--4361c4e6ae1b083e9e0508a7b40eb215bccd265c4bed00137cc7d112e890
Content-Disposition: form-data; name="text"

{"DisplayText":"good","Language":"cn"}
--4361c4e6ae1b083e9e0508a7b40eb215bccd265c4bed00137cc7d112e890
Content-Disposition: form-data; name="text2"

{"look":"me"}
--4361c4e6ae1b083e9e0508a7b40eb215bccd265c4bed00137cc7d112e890
Content-Disposition: form-data; name="text"

good
--4361c4e6ae1b083e9e0508a7b40eb215bccd265c4bed00137cc7d112e890--
-Jfa-string

和-Jfa语法类似,不解析@符号

-H 或者 --header

设置http 头,可以指定多个

./gurl http -H "header1:value1" -H "header2:value2" http://xxx.xxx.xxx.xxx:port
-url

设置http url的地址, 可以使用简写

-oflag

-oflag 一般和-o选项配合使用(控制写文件的行为)

  • -oflag append 默认-o的行为是新建文件然后写入,如果开启-ac -an选项,可以使用append肥所有的结果保存到一个文件中
  • -oflag line 如果服务端返回的结果,想使用换行符分隔
    小提示: -oflag 后面的命令可以组合使用 "append|line"的意思是:把服务端的输出追加到某个文本中,并用'\n'分隔符

高级主题(stream功能)

-I

打开input模式

-R

打开列表文件, 可以使用-input-fields 指定分割符,默认是空格

-skey

给默认的名字取个别名,相当于取个好听的变量名,方便后面引用

-r

从流里面读取数据

-w

结果输出到流

-merge

把输入流里面的结果和识别结果组成大的结果,写到输出流

-O

打开output模式

-wkey

控制写出的json key

|

管道符主要拼接多个gurl功能块

批量访问多个url

开5个线程访问url.list里面的url列表

cat url.list

github.com
www.baidu.com
www.qq.com
www.taobao.com

gurl http -I -R url.list -skey "url=rf.col.0" "|" -ac 5 -r -w -merge "{url}" -o "/dev/null" "|" -O -wkey "status_code"

TODO

  • 集群模式
  • GUI

websocket 子命令

命令行选项

guonaihong https://github.com/guonaihong/wsurl

Usage of gurl:
  -A, --user-agent string
    	Send User-Agent STRING to server (default "gurl")
  -H, --header string[]
    	Pass custom header LINE to server (H) (default [])
  -I, --input-model
    	open input mode
  -O, --output-mode
    	open output mode
  -R, --input-read string
    	open input file
  -W, --output-write string
    	open output file
  -ac int
    	Number of multiple requests to make (default 1)
  -an int
    	Number of requests to perform (default 1)
  -bench
    	Run benchmarks test
  -binary
    	Send binary messages instead of utf-8
  -close
    	Send close message
  -duration string
    	Duration of the test
  -fsa, --first-send-after string
    	Wait for the first time before sending
  -input-fields string
    	sets the field separator (default " ")
  -l string
    	Listen mode, websocket echo server
  -ld, --last-packet string
    	The last packet is written to the connection
  -m, --merge
    	Combine the output results into the output
  -o, --output string
    	Write to FILE instead of stdout (default "stdout")
  -p, --packet string[]
    	Data packet to be send per connection
  -r, --read-stream
    	Read data from the stream
  -rate int
    	Requests per second
  -send-rate string
    	How many bytes of data in seconds
  -skey, --input-setkey string
    	Set a new name for the default key
  -url string
    	Specify a URL to fetch
  -w, --write-stream
    	Write data from the stream
  -wkey, --write-key string
    	Key that can be write
-H 或header

设置websocket 的header和http header类似

-p 或 --packet

发送websocket body数据到服务端,支持@符号打开一个文件, 如果不接@直接把-d后面字符串发送到服务端

  wsurl -p "good" :12345
  wsurl -p "@./file" :12345
-send-rate
# 指定每多少ms发多少字节
wsurl -send-rate "8000B/250ms" -url ws://127.0.0.1:24986
-binary

默认是以text格式作为websocket消息类型, 加上-binary就以text作为消息类型

-ld

发送最后一个websocket包的内容

  wsurl -ld "good" :12345
  wsurl -ld "@./file" :12345
-url

设置websocket的url

-ac

指定线程数, 开ac个线程, 发送an个请求

wsurl -an 10 -ac 2 -F text=good :1234
-an

指定次数

-duration

和-bench选项一起使用,可以控制压测时间,支持单位符,s(秒), m(分), h(小时), d(天), w(周), M(月), y(年), ms(毫秒) 也可以混合使用 -duration 1m10s

-rate

指定每秒写多少条,目前只有打开-bench选项才起作用

-close

客户端主动发起close消息给服务端

-bench

压测模式 wsurl -bench -ac 20 -an 10000 -url :33333 -close

Connecting to to ws://127.0.0.1:33333
    Opened            1000 connections: [2018-08-23 20:50:55.987]
    Opened            2000 connections: [2018-08-23 20:50:56.129]
    Opened            3000 connections: [2018-08-23 20:50:56.266]
    Opened            4000 connections: [2018-08-23 20:50:56.409]
    Opened            5000 connections: [2018-08-23 20:50:56.552]
    Opened            6000 connections: [2018-08-23 20:50:56.684]
    Opened            7000 connections: [2018-08-23 20:50:56.835]
    Opened            8000 connections: [2018-08-23 20:50:56.098]
    Opened            9000 connections: [2018-08-23 20:50:57.125]
    Opened           10000 connections: [2018-08-23 20:50:57.268]

    Finished 10000 connections

Concurrency Level:        20
Time taken for tests:     1.432677765s
Connected:                10000
Disconnected:             0
Failed:                   0
Total transferred:        0
Total received            0
Requests per second:      6979 [#/sec] (mean)
Time per request:         716338.883 [ms] (mean)
Time per request:         71.634 [ms] (mean, across all concurrent requests)
Transfer rate:            0.000 [Kbytes/sec] received

Percentage of the requests served within a certain time (ms)
    50%    2.00ms
    66%    2.00ms
    75%    3.00ms
    80%    3.00ms
    90%    4.00ms
    95%    6.00ms
    98%    7.00ms
    99%    9.00ms
    100%   21.00ms

高级主题(stream功能)

-I

打开input模式

-R

打开列表文件, 可以使用-input-fields 指定分割符,默认是空格

-skey

给默认的名字取个别名,相当于取个好听的变量名,方便后面引用

-r

从流里面读取数据

-w

结果输出到流

-merge

把输入流里面的结果和识别结果组成大的结果,写到输出流

-O

打开output模式

-wkey

控制写出的json key

|

管道符主要拼接多个gurl功能块

tcp, udp 子命令用法

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Gurl is a performance testing tool. The supported protocols are http, websocket, tcp. Of course, it also supports access in non-bench mode. gurl是性能测试工具,支持的协议有http, websocket,tcp。当然也支持非bench模式下的访问 展开 收起
Go
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/guonaihong/gurl.git
git@gitee.com:guonaihong/gurl.git
guonaihong
gurl
gurl
master

搜索帮助