压力测试工具ab - Apache HTTP server benchmarking tool
搞互联网开发,压力测试必不可少。压力测试的工具很多,我用过ab和JMeter,今天主要讲ab的用法。
1、ab是什么
ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.
2、官网
2.1、文档地址
http://httpd.apache.org/docs/2.4/programs/ab.html
2.2、如何找到文档


2.3、下载安装

3、用法
3.1、测试GET请求
D:\Apache24\bin>ab -n -c http://www.baidu.com/
This is ApacheBench, Version . <$Revision: $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.baidu.com (be patient)
Completed requests
Completed requests
Finished requests Server Software: BWS/.
Server Hostname: www.baidu.com
Server Port: Document Path: /
Document Length: bytes Concurrency Level:
Time taken for tests: . seconds
Complete requests:
Failed requests:
(Connect: , Receive: , Length: , Exceptions: )
Total transferred: bytes
HTML transferred: bytes
Requests per second: . [#/sec] (mean)
Time per request: . [ms] (mean)
Time per request: . [ms] (mean, across all concurrent requests)
Transfer rate: . [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: .
Processing: .
Waiting: .
Total: . Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request) D:\Apache24\bin>
D:\Apache24\bin>ab -n -c http://localhost:8080/coupon/getByMechantId.json?merchantId=10002
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software:
Server Hostname: localhost
Server Port: Document Path: /coupon/getByMechantId.json?merchantId=
Document Length: bytes Concurrency Level:
Time taken for tests: 0.361 seconds
Complete requests:
Failed requests:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 276.97 [#/sec] (mean)
Time per request: 180.527 [ms] (mean)
Time per request: 3.611 [ms] (mean, across all concurrent requests)
Transfer rate: 317.81 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0.4
Processing: 44.7
Waiting: 45.0
Total: 44.8 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request) D:\Apache24\bin>
3.2、测试POST请求
D:\Apache24\bin>ab -n -c -p D:\data.json -T application/json http://localhost:8080/coupon/save.json
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient)
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Finished requests Server Software:
Server Hostname: localhost
Server Port: Document Path: /coupon/save.json
Document Length: bytes Concurrency Level:
Time taken for tests: 3.306 seconds
Complete requests:
Failed requests:
Total transferred: bytes
Total body sent:
HTML transferred: bytes
Requests per second: 302.52 [#/sec] (mean)
Time per request: 661.121 [ms] (mean)
Time per request: 3.306 [ms] (mean, across all concurrent requests)
Transfer rate: 56.43 [Kbytes/sec] received
127.92 kb/s sent
184.35 kb/s total Connection Times (ms)
min mean[+/-sd] median max
Connect: 0.5
Processing: 432.2
Waiting: 432.3
Total: 432.2 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request) D:\Apache24\bin>
3.3、带Cookie
D:\Apache24\bin>ab -n -c -C token= -p D:\data.json -T application/json http://localhost:8080/coupon/save.json

data.json是这样的:
{
"merchantId": ,
"couponName": "我妈最美",
"couponType": ,
"parValue": ,
"quantity": ,
"releaseStartTime": "2018-05-13 00:00:00",
"releaseEndTime": "2018-05-13 23:59:59",
"limitType": ,
"limitNum": ,
"remark": "妈妈,您辛苦了!"
}
4、Linux下使用ab
yum install httpd-tools


java -jar cjs-springboot-example.jar &

用法没变
5、代码
package com.cjs.boot.controller; import com.cjs.boot.domain.entity.CouponInfo;
import com.cjs.boot.response.RespResult;
import com.cjs.boot.service.CouponInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import javax.validation.constraints.NotNull;
import java.util.List; @Controller
@RequestMapping("/coupon")
@Validated
public class CouponController extends BaseController { @Autowired
private CouponInfoService couponInfoService; @GetMapping("/detail.html")
public ModelAndView detail(@NotNull(message = "ID不能为空") Long id) {
ModelAndView modelAndView = new ModelAndView("coupon/detail");
// TODO 查询
return modelAndView;
} @GetMapping("/getByMechantId.json")
@ResponseBody
public RespResult<List<CouponInfo>> getByMechantId(Integer merchantId) {
List<CouponInfo> list = couponInfoService.getByMerchantId(merchantId);
return new RespResult<List<CouponInfo>>(list);
} @GetMapping("/deleteByMechantId.json")
@ResponseBody
public RespResult<List<CouponInfo>> deleteByMerchantId(Integer merchantId) {
couponInfoService.deleteByMerchantId(merchantId);
return RespResult.success();
} @GetMapping("/getById.json")
@ResponseBody
public RespResult<CouponInfo> getById(Long id) {
CouponInfo couponInfo = couponInfoService.getById(id);
return new RespResult<CouponInfo>(couponInfo);
} @GetMapping("/deleteById.json")
@ResponseBody
public RespResult deleteById(Long id) {
couponInfoService.deleteById(id);
return RespResult.success();
} @GetMapping("/add.html")
public ModelAndView add() {
return new ModelAndView("coupon/add");
} @PostMapping("/save.json")
@ResponseBody
public RespResult save(@RequestBody CouponInfo couponInfo, @CookieValue(required = false) String token) {
couponInfoService.save(couponInfo);
return RespResult.success();
}
}
package com.cjs.boot; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.cjs.boot.event.BlackListListener;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.EnableAsync; import java.util.ArrayList;
import java.util.List; //@MapperScan("com.cjs.boot.mapper")
@EnableCaching
@EnableAsync
@SpringBootApplication
public class CjsSpringbootExampleApplication { public static void main(String[] args) {
SpringApplication.run(CjsSpringbootExampleApplication.class, args); // SpringApplication springApplication = new SpringApplication(CjsSpringbootExampleApplication.class);
// springApplication.addListeners(new BlackListListener());
// springApplication.run(args); } @Bean
public ErrorPageRegistrar errorPageRegistrar() {
return new ErrorPageRegistrar() {
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400.html"));
registry.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/403.html"));
registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
registry.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html"));
}
};
} @Bean
public HttpMessageConverters fastJsonHttpMessageConverters(){
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fastJsonHttpMessageConverter.setSupportedMediaTypes(mediaTypes);
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastJsonHttpMessageConverter); } }

参考
https://www.cnblogs.com/EthanCai/archive/2014/05/11/3721656.html
https://blog.csdn.net/wx19900503/article/details/56847264
https://www.jianshu.com/p/e3793ae91a62
https://blog.csdn.net/dreamer2020/article/details/52904686
http://wetest.qq.com/
http://wetest.qq.com/gaps/
压力测试工具ab - Apache HTTP server benchmarking tool的更多相关文章
- Apache中压力测试工具ab的操作说明
1.压力测试工具ab(ApacheBench)的简单说明 1) 网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个 ...
- Apache自带压力测试工具ab用法简介
ab命令原理 ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL进行访问.它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试nginx.lighthttp ...
- apache自带压力测试工具ab的使用及解析
当你搭建了apache服务器并在上面部署了web网站,在网站运行前,为了使apache服务器的性能得到更好的应用,我们可以先对其进行压力测试.进行压力测试其实非常简单,我们也不用再额外下载安装什么测试 ...
- linux下web压力测试工具ab使用及详解
APACHE自带的测试工具AB(apache benchmark).在APACHE的bin目录下.格式: ./ab [options] [http://]hostname[:port]/path参数: ...
- 压力测试工具ab及centos下单独安装方法
压力测试工具Ab简介 Apache安装包中自带的压力测试工具 Apache Benchmark(简称ab) 简单易用,这里就采用 ab作为压力测试工具了. 1.独立安装 ab运行需要依赖apr-uti ...
- httpd的压力测试工具-ab工具使用案例
httpd的压力测试工具-ab工具使用案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.httpd自带的工具程序 事实上,在我们安装完Apache之后,它默认就会给我们安 ...
- PHP测试与优化(1)-- Apache自带的压力测试工具ab(apache bench) - 简单使用
ab是apache自带的网站压力测试工具,能够测试网站在一定时间内的发生高并发时的反应. 使用 1.进入apache的bin文件夹 2.模拟并发级别为100,请求数为1000个的api数据请求数量测试 ...
- 压力测试工具Ab简介
Apache安装包中自带的压力测试工具 Apache Benchmark(简称ab) 简单易用,这里就采用 ab作为压力测试工具了. 1.独立安装 通过 yum-utils中的yumdownload ...
- 压力测试工具ab及centos下单独安装方法 nginx和tomcat静态资源的性能测试
Apache安装包中自带的压力测试工具Apache Benchmark(简称ab)简单易用,这里采用ab作为压国测试工具. 独立安装: ab运行需要信赖apr-util包: # yum install ...
随机推荐
- javascript 实战总结
JavaScript的简单的知识前面已经总结 欢迎交流学习,学习靠的是理论+实践, 通过姜昊老师的JavaScript专题训练,加深了对理论知识的理解,学习新的语言越来越发现熟悉的背景,基础内容是 ...
- Android和iOS中Cocos2D日志为什么会出现skip frames
在你运行app在Android或iOS设备或iOS模拟器中时,日志里往往会出现一行: I/Choreographer(28956): Skipped 159 frames! The applicati ...
- CSS3 Media Queries 简介
原文链接:Introduction to CSS3 Media Queries 原文日期: 2014年2月21日 翻译日期: 2014年2月26日 翻译人员: 铁锚 简介 随着移动设备的日益普及,we ...
- Memcached学习笔记 — 第四部分:Memcached Java 客户端-gwhalin(1)-介绍及使用
介绍 Memcached java client是官方推荐的最早的memcached java客户端.最新版本:java_memcached-release_2.6.1. 官方下载地址:http ...
- Lucene 学习资料
个机制的结合.关于中文的语言分析算法,大家可以在Google查关键词"wordsegment search"能找到更多相关的资料. 安装和使用 下载:http://jakarta. ...
- windows linux—unix 跨平台通信集成控制系统
首先,我们可以用到这个开源的开发包: mdk(Micro-Development-Kit)微量级软件开发包,提供几个常用类,主要实现了一个高性能的并发服务器引擎 使用c++开发,是一个跨平台的开发包, ...
- objc:NSDateFormatter使用备忘
NSDateFormatter类的实例可以将字符串的日期表示转换为NSDate对象或者反向转换. 如果只要显示日期不需要时间,则可以用-setDateStyle方法来设置显示日期的格式,有以下几种: ...
- Activity之间传递大数据问题
Android开发人员都知道,Intent适用于在不同的Activity之间传递数据,包括参数.字符串.以及序列化的对象等.但是笔者所做的项目用到了使用Intent 传递Bitmap图片对象,图片的数 ...
- 如何设置静态IP
首先在CMD命令行ipconfig查看临时分配的IP地址: 然后打开我的"网络"--->"本地连接"--->IPv4--->属性 电信DNS劫 ...
- obj-c编程19:关联对象
对于一些无法子类化的实例对象来说,如果希望将一个对象与其绑定该如何做呢? 以下示例虚构了一个HyConsoleAlert类,User类将会使用该类在控制台显示定制的告警.如果User中包括多个Aler ...