duanhui3759 2017-07-05 04:13
浏览 43
已采纳

通过使用使用bash脚本生成的动态URL使用围攻进行基准测试

I want to bench test my website with 1M requests with different urls using siege, I need to know can I create a bash script to do a random loop or php script to read urls from database and create dynamic urls and give this urls to siege command to perform bench test ?

for example I have this type of banner_sizes :

[
    {
        "id": 1,
        "size": "normal_x970h90",
    },
    {
        "id": 2,
        "size": "normal_x234h60",
    },
    {
        "id": 3,
        "size": "normal_x468h60",
    },
    {
        "id": 4,
        "size": "normal_x300h600",
    },
    {
        "id": 5,
        "size": "normal_x120h600",
    },
    {
        "id": 6,
        "size": "normal_x160h600",
    },
    {
        "id": 7,
        "size": "normal_x120h240",
    },
    {
        "id": 8,
        "size": "normal_x300h250",
    },
    {
        "id": 9,
        "size": "normal_x250h250",
    },
    {
        "id": 10,
        "size": "normal_x600h300",
    },
    {
        "id": 11,
        "size": "normal_x728h90",
    },
    {
        "id": 12,
        "size": "normal_x300h100",
    },
    {
        "id": 13,
        "size": "normal_x125h125",
    }
]

And also I have these id's :

 [
  0 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#915}
  ]
  1 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#926}
  ]
  2 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#924}
  ]
  3 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#913}
  ]
  4 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#929}
  ]
  5 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#862}
  ]
  6 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#863}
  ]
  7 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#864}
  ]
  8 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#865}
  ]
  9 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#928}
  ]
  10 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#927}
  ]
  11 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#917}
  ]
  12 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#918}
  ]
  13 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#899}
  ]
  14 => array:1 [
    "_id" => MongoDB\BSON\ObjectID {#898}
  ]
]

I need to create these type of url using above info :

www.example.come/api/is/normal_x234h60/899
www.example.com/api/is/normal_x600h300/898

and more like this.

Is there a way to create this urls and put them in txt file and then run my siege command :

   siege -c10000 -b -t30m -f urls.txt

Or using apache ab bench test ?

  • 写回答

1条回答 默认 最新

  • doudou1897 2017-07-06 06:16
    关注

    I've found a solution for this matter, I've created a php file which it connects to mysql and mongodb database and read the data, then in a nested for loop I created those urls I needed and stored them in txt file. then I just needed to run the siege command :

    siege -c10000 -b -t30m -f urls.txt
    

    but because of siege issue with big size requests I created a bash script which will read each line of urls.txt file and runs an apache ab test using each url to stress test with dynamic urls my application.

    php code to create urls :

            $seats = Seat::where('status', 'ACTIVE')->get();
            $s_count = Seat::where('status', 'ACTIVE')->count();
    
    
            $bs = Banners::where('status', 'enable')->get();
            $bs_count = Banners::where('status', 'enable')->count();
    
            $url = Config('conf.APP_PATH') . "/api/is/";
            $url_array = array();
    
            for ($i = 0; $i < $s_count; $i++) {
                for ($j = 0; $j < $bs_count; $j++) {
                    $url_array[] = $url . $bs[$j]['size'] . "/" . $seats[$i]['_id']."
    ";
                }
            }
    
    
            File::put('./url.txt',$url_array);
    

    bash script to run multiple bench test :

    while read LINE; do
       cmnd="./ab -n10000 -c100 "
       cmnd=${cmnd}"$LINE"
       eval $cmnd
       cmnd=''
    done < urls.txt
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?