• web service压测工具:siege安装及使用介绍


    Siege

    web服务器性能测试的工具有很多,比如ab,siege等,小组使用siege测试工具进行性能测试。

    介绍

    Siege是一个http/https回归测试和基准测试工具。它旨在让Web开发人员在压力下测试其代码的性能,以了解它部署在互联网上的表现。它允许用户使用可配置数量的并发模拟用户访问Web服务器。这些用户将网络服务器置于“围攻下”。围攻的持续时间是在传输中测量,模拟用户的总和以及每个模拟用户重复点击服务器的次数。因此20个并发用户请求50次就是1000次传输。整个性能测量包括测试总耗时时长,传输的数据量(包括handlers),服务器的响应时间,事务速率,吞吐量,并发性以及返回的正常次数。这些指标会在每次运行结束时进行量化和报告,各个指标代表什么含义会在下面介绍。

    Siege基本上有三种操作模式,回归,互联网模拟和暴力。它可以从配置文件中读取大量URL,并逐个(回归)或随机(互联网模拟)运行它们,或者用户可以在命令行中使用命令行简单地敲击单个URL;

    安装

    • 安装包安装
    wget http://download.joedog.org/siege/siege-latest.tar.gz
    $ tar zxf siege-latest.tar.gz
    $ cd siege-4.0.2/
    $ ./configure
    $ sudo make
    $ sudo make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 命令行
    yum install siege
    或者
    apt install siege
    
    • 1
    • 2
    • 3

    查看是否安装成功:

    查看siege安装路径:
    $ which siege
    /usr/local/bin/siege
    
    查看siege版本:
    $ siege -V
    SIEGE 4.0.2
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    参数介绍

    SIEGE 4.0.2
    Usage: siege [options]
           siege [options] URL
           siege -g URL
    Options:
      -V, --version             VERSION, prints the version number.
      -h, --help                HELP, prints this section.
      -C, --config              CONFIGURATION, show the current config.
      -v, --verbose             VERBOSE, prints notification to screen.
      -q, --quiet               QUIET turns verbose off and suppresses output.
      -g, --get                 GET, pull down HTTP headers and display the
                                transaction. Great for application debugging.
      -c, --concurrent=NUM      CONCURRENT users, default is 10
      -r, --reps=NUM            REPS, number of times to run the test.
      -t, --time=NUMm           TIMED testing where "m" is modifier S, M, or H
                                ex: --time=1H, one hour test.
      -d, --delay=NUM           Time DELAY, random delay before each requst
      -b, --benchmark           BENCHMARK: no delays between requests.
      -i, --internet            INTERNET user simulation, hits URLs randomly.
      -f, --file=FILE           FILE, select a specific URLS FILE.
      -R, --rc=FILE             RC, specify an siegerc file
      -l, --log[=FILE]          LOG to FILE. If FILE is not specified, the
                                default is used: PREFIX/var/siege.log
      -m, --mark="text"         MARK, mark the log file with a string.
                                between .001 and NUM. (NOT COUNTED IN STATS)
      -H, --header="text"       Add a header to request (can be many)
      -A, --user-agent="text"   Sets User-Agent in request
      -T, --content-type="text" Sets Content-Type in request
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    调用

    当服务启动后,就可以测试调用了:

    GET 请求方式调用
    • 单条地址 重复测试:
    siege -r 10 -c 25  http://0.0.0.0:5000/xxx?user=10
    
    • 1
    • 文件测试:文件里面准备好的多条访问地址(类似于上述的url后跟参数),可以通过参数控制选择是逐条测试或者随机测试:
    siege -c 15 -r 50 -b -f test_file &> log.press.$RANDOM &
    
    • 1

    POST请求方式调用

    • 单条地址 重复测试:
    siege  -H "Content-Type:application/json"  -c 10 -r 10 http://0.0.0.0:5000/xxx POST p1=v1&p2=v2
    
    • 1
    • json文件测试
    # 新建json文件
    
    # 1.vim test.json
    
    {
        "p1": p1,
        "p2": p2
    }
    
    # 2. 测试语句
    
    # 每秒10个并发跑10次 test.json 为发送的数据内容
    siege  -H "Content-Type:application/json"  -c 10 -r 10  'http://0.0.0.0:5000/xxx POST < /tmp/test.json'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    注意: 如果url中含有空格和中文,要先进行url编码,否则siege发送的请求url不准确

    在这里插入图片描述

    结果参数介绍

    • -c 25: 25 个仿真用户, -r 10: 每个用户请求的次数;

    • Transactions:服务器受到的请求次数;

    • Elapsed time: 整个测试阶段总耗时;

    • Data transferred:每个仿真用户传输数据大小的总和;

    • Response time:每次请求耗时的平均时间;

    • Transaction rate: 服务器每秒能够处理的请求数量;

    • Throughput: 服务器每秒传输的字节数;

    • Concurrency: 平均同时连接数;

    • Successful transactions: 成功连接次数;

    • Failed transactions: 失败连接次数;

    • Longest transactions:最长的一次请求时间;

    • Shortest transactions:最短的一次请求时间;

    参考

  • 相关阅读:
    国内外数据保护(灾备、备份、恢复、复制、归档)厂商
    使用pushd高效的切换目录
    setState是同步更新还是异步更新的
    测试开发面经
    Java反射学习笔记--使用示例
    深度学习——python中的广播
    【C语言】memmove()函数(拷贝重叠内存块函数详解)
    CV轻量级backbone模型小抄(1)
    2017年某高校848数据结构真题复习
    宁波银行金融科技部2023届校招开始了!内推码:90OF50
  • 原文地址:https://blog.csdn.net/uncle_ll/article/details/126484107