搞互联网开发,压力测试必不可少。压力测试的工具很多,我用过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的更多相关文章

  1. Apache中压力测试工具ab的操作说明

    1.压力测试工具ab(ApacheBench)的简单说明 1)     网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个 ...

  2. Apache自带压力测试工具ab用法简介

    ab命令原理 ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL进行访问.它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试nginx.lighthttp ...

  3. apache自带压力测试工具ab的使用及解析

    当你搭建了apache服务器并在上面部署了web网站,在网站运行前,为了使apache服务器的性能得到更好的应用,我们可以先对其进行压力测试.进行压力测试其实非常简单,我们也不用再额外下载安装什么测试 ...

  4. linux下web压力测试工具ab使用及详解

    APACHE自带的测试工具AB(apache benchmark).在APACHE的bin目录下.格式: ./ab [options] [http://]hostname[:port]/path参数: ...

  5. 压力测试工具ab及centos下单独安装方法

    压力测试工具Ab简介 Apache安装包中自带的压力测试工具 Apache Benchmark(简称ab) 简单易用,这里就采用 ab作为压力测试工具了. 1.独立安装 ab运行需要依赖apr-uti ...

  6. httpd的压力测试工具-ab工具使用案例

    httpd的压力测试工具-ab工具使用案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   一.httpd自带的工具程序 事实上,在我们安装完Apache之后,它默认就会给我们安 ...

  7. PHP测试与优化(1)-- Apache自带的压力测试工具ab(apache bench) - 简单使用

    ab是apache自带的网站压力测试工具,能够测试网站在一定时间内的发生高并发时的反应. 使用 1.进入apache的bin文件夹 2.模拟并发级别为100,请求数为1000个的api数据请求数量测试 ...

  8. 压力测试工具Ab简介

    Apache安装包中自带的压力测试工具 Apache Benchmark(简称ab) 简单易用,这里就采用 ab作为压力测试工具了. 1.独立安装 通过 yum-utils中的yumdownload  ...

  9. 压力测试工具ab及centos下单独安装方法 nginx和tomcat静态资源的性能测试

    Apache安装包中自带的压力测试工具Apache Benchmark(简称ab)简单易用,这里采用ab作为压国测试工具. 独立安装: ab运行需要信赖apr-util包: # yum install ...

随机推荐

  1. 《java入门》第一季之类(String类字符串一旦被赋值就没法改变)

    毫无疑问,String类是java里面最重要的类之一.因此它有很多方法需要了解和掌握. 字符串一旦被赋值,值就不能发生改变: package cn.itcast_02; /* * 字符串的特点:一旦被 ...

  2. 01_JNI是什么,为什么使用,怎么用JNI,Cygwin环境变量配置,NDK案例(使用Java调用C代码),javah命令使用

    1 什么是JNI JNI Java本地开发接口 JNI是一个协议,这个协议用来沟通java代码和外部的本地代码(C/C++) 通过这个协议,java代码就可以调用外部的C/C++代码,外部的C/C++ ...

  3. div+css基础教程

    本文存下来作为备忘. 第一节  了解div+css 一.什么是div+css div元素是html(超文本语言)中的一个元素,是标签,用来为html文档内大块(block-level)的内容提供结构和 ...

  4. ffplay的快捷键以及选项

    ffplay是ffmpeg工程中提供的播放器,功能相当的强大,凡是ffmpeg支持的视音频格式它基本上都支持.甚至连VLC不支持的一些流媒体都可以播放(比如说RTMP),但是它的缺点是其不是图形化界面 ...

  5. java工具类(五)之日期格式字符串与日期实现互转

    JAVA字符串转日期或日期转字符串 项目开发过程中需要实现日期格式的字符串与日期进行互转,并进行日期的加减操作. Demo如下: package weiming.lmapp.utils; import ...

  6. 求剁手的分享,如何简单开发js图表

    前段时间做的一个项目里需要用到js图表,在网上找了下,大概找到了highcharts.fusioncharts这些国外产品. 因为都收费,虽然有盗版,我也不敢用,万一被找上们来就砸锅卖铁了要.自己写j ...

  7. iOS监听模式系列之通知中心

    补充--通知中心 对于很多初学者往往会把iOS中的本地通知.推送通知和iOS通知中心的概念弄混.其实二者之间并没有任何关系,事实上它们都不属于一个框架,前者属于UIKit框架,后者属于Foundati ...

  8. nfc近场通信

    NFC简介: Near Field Communication 近场通信,是一种数据传输技术. 与wifi.蓝牙.红外线等数据传输技术的一个主要差异就是有效距离一般不能超过4cm. NFC支持3种工作 ...

  9. 面试之路(8)-BAT面试题之数组和链表的区别

    两种数据结构都是线性表,在排序和查找等算法中都有广泛的应用 各自的特点: 数组: 数组是将元素在内存中连续存放,由于每个元素占用内存相同,可以通过下标迅速访问数组中任何元素.但是如果要在数组中增加一个 ...

  10. LeetCode(35)-Path Sum

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...