apache ab测试并发多次实例与单次实例

本文通过实验对比了5000次请求下,不同数量的类实例化对并发性能的影响,结果显示,随着实例化次数增加,处理时间相应延长。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

请求5000次,并发数1000
实例化1次和实例化5次
结果:相差5秒,即并发相差5毫秒( 15815.625毫秒, 20234.375毫秒
总结:其实有这个差距,也就是因为5次实例化,多了4次的处理数据,处理数据越大,速度肯定是越慢。所以很多服务器都会有专门的图片服务器,以减轻服务器的压力。网站服务器专门用来输出文字。

<?php
/**
*类名:A
*主要功能:从0-1000的数字相加
*5000请求,1000次并发 实例化1次。结果在最下方
*ab -n 5000 -c 1000 http://192.168.57.131/abnewc/a.php
*/

class a
{
public $counts = 0;

function __construct()
{
$this->init();
}

private function init()
{
for($i = 0; $i < 1000; $i++)
{
$this->counts = $this->counts + $i;
}

}
}


$last_time = time();
$a1 = new a;
$diff_time = time() - $last_time;

echo('类a运行0-1000的数字相加,被实例化2次,5000请求并发数1<br><br>');
echo('运行时间:'.$diff_time.'秒');


/**
C:\wamps\bin\apache\Apache2.2.21\bin>ab -n 5000 -c 1000 http://192.168.57.131/abnewc/a.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.57.131 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software: Apache/2.2.12
Server Hostname: 192.168.57.131
Server Port: 80

Document Path: /abnewc/a.php
Document Length: 74 bytes

Concurrency Level: 1000
Time taken for tests: 79.078 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 1420000 bytes
HTML transferred: 370000 bytes
Requests per second: 63.23 [#/sec] (mean)
Time per request: 15815.625 [ms] (mean)
Time per request: 15.816 [ms] (mean, across all concurrent requests)
Transfer rate: 17.54 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 16 209.5 0 3109
Processing: 78 13701 4074.6 15625 21563
Waiting: 31 8055 4706.7 6609 18656
Total: 78 13717 4074.7 15625 21563

Percentage of the requests served within a certain time (ms)
50% 15625
66% 15781
75% 15828
80% 15984
90% 16125
95% 16234
98% 18750
99% 21531
100% 21563 (longest request)


<?php
/**
*类名:A
*主要功能:从0-1000的数字相加
*5000请求,1000次并发 实例化5次。结果在最下方
*ab -n 5000 -c 1000 http://192.168.57.131/abnewc/b.php
*/

class a
{
public $counts = 0;

function __construct()
{
$this->init();
}

private function init()
{
for($i = 0; $i < 1000; $i++)
{
$this->counts = $this->counts + $i;
}

}
}


$last_time = time();
$a1 = new a;
$a2 = new a;
$a3 = new a;
$a4 = new a;
$a5 = new a;
$diff_time = time() - $last_time;

echo('类a运行0-1000的数字相加,被实例化2次,5000请求并发数1000<br><br>');
echo('运行时间:'.$diff_time.'秒');


/**
C:\wamps\bin\apache\Apache2.2.21\bin>
C:\wamps\bin\apache\Apache2.2.21\bin>ab -n 5000 -c 1000 http://192.168.57.131/abnewc/b.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.57.131 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software: Apache/2.2.12
Server Hostname: 192.168.57.131
Server Port: 80

Document Path: /abnewc/b.php
Document Length: 77 bytes

Concurrency Level: 1000
Time taken for tests: 101.172 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 1435000 bytes
HTML transferred: 385000 bytes
Requests per second: 49.42 [#/sec] (mean)
Time per request: 20234.375 [ms] (mean)
Time per request: 20.234 [ms] (mean, across all concurrent requests)
Transfer rate: 13.85 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 20 234.6 0 3125
Processing: 141 18164 5689.0 19406 43797
Waiting: 47 10633 5939.5 9719 43781
Total: 141 18184 5690.2 19406 43813

Percentage of the requests served within a certain time (ms)
50% 19406
66% 21203
75% 21828
80% 21922
90% 22000
95% 24344
98% 24625
99% 24719
100% 43813 (longest request)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值