压力测试工具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 ...
随机推荐
- 环境连接报错(最大连接数超过) APP-FND-01516
数据库用户登录服务器,sqlplu 解决办法: 先把界面上要保存的操作保存好 应用用户登录,切换到ora用户 杀掉进程 ps -fu ora | grep LOCAL=NO|grep -v grep| ...
- 【翻译】在Ext JS和Sencha Touch中创建自定义布局
原文:Creating Custom Layouts in Ext JS and Sencha Touch 布局系统是Sencha框架中最强大和最独特的一部分.布局会处理应用程序中每个组件的大小和位置 ...
- 《java入门第一季》之面向对象(接口收尾)
通过案例的形式,结束接口部分. /* 猫狗案例,加入跳高的额外功能 分析:从具体到抽象 猫: 姓名,年龄 吃饭,睡觉 狗: 姓名,年龄 吃饭,睡觉 由于有共性功能,所以,我们抽取出一个父类: 动物: ...
- Android群英传笔记——第十二章:Android5.X 新特性详解,Material Design UI的新体验
Android群英传笔记--第十二章:Android5.X 新特性详解,Material Design UI的新体验 第十一章为什么不写,因为我很早之前就已经写过了,有需要的可以去看 Android高 ...
- LeetCode之“树”:Validate Binary Search Tree
题目链接 题目要求: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is ...
- iOS中NSBundle的介绍
bundle是一个目录,其中包含了程序会使用到的资源.这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in).对应bundle,cocoa提供了类NSBund ...
- 数据包接收系列 — IP协议处理流程(一)
本文主要内容:在接收数据包时,IP协议的处理流程. 内核版本:2.6.37 Author:zhangskd @ csdn blog IP报头 IP报头: struct iphdr { #if defi ...
- android 获取Bitmap位图所占用的内存大小
今天在看Universal-Image-Loader源码的时候,在对图片的超过用户在所设的阈值的时候,系统会调用GC将LinkHashMap比较靠底层的图片引用去掉,这里涉及到一个技术单个图片的文图大 ...
- RHEL6.4安装nginx
RHEL6.4安装nginx 下载nginx-1.6.1.tar.gz, 解压进入目录: $ yum install pcre-devel $ ./configure --with-http_ssl_ ...
- LeetCode刷题之合并排序链表
合并两个有序链表并返回一个新的列表.新列表应该由连接在一起的节点前两个列表 给定实例:Input: 1->2->4, 1->3->4Output: 1->1->2- ...