0%

使用命令行执行

首先看一下jmeter命令中可用的参数

1
2
3
4
5
6
7
-h 帮助 -> 打印出有用的信息并退出
-n 非 GUI 模式 -> 在非 GUI 模式下运行 JMeter
-t 测试文件 -> 要运行的 JMeter 测试脚本文件
-l 日志文件 -> 记录结果的文件
-r 远程执行 -> 启动远程服务
-H 代理主机 -> 设置 JMeter 使用的代理主机
-P 代理端口 -> 设置 JMeter 使用的代理主机的端口号

既然是使用命令行,那么就不需要GUI,则使用-n

1
./jmeter -n -t /home/jmeter/test-example/HTTP请求.jmx -l /home/jmeter/test-example/result/result.csv

CAS操作

之前说在java.util.concurrent.atomic包下提供的原子操作类底层使用的是CAS,那么什么是CAS呢,CAS的全称为Compare And Swap,比较并替换,CAS机制中使用了3个基本操作数:内存地址V,旧的预期值A,要修改的新值B

在进行变量更新时,需要对比预期值A和内存地址V中的实际值,如果两者相同,才会将V对应的的值改为B

AtomicInteger为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// unsafe提供了硬件级别的原子操作
private static final Unsafe unsafe = Unsafe.getUnsafe();
// 存储value在AtomicInteger中的偏移量
private static final long valueOffset;
// 存储AtomicInteger的int值,该属性需要借助volatile关键字保证其在线程间是可见的
private volatile int value;

static {
try {
// valueOffset表示的是AtomicInteger对象value成员变量在内存中的偏移量,可以当做是value变量的内存地址
valueOffset = unsafe.objectFieldOffset
(AtomicInteger.class.getDeclaredField("value"));
} catch (Exception ex) { throw new Error(ex); }
}

public final boolean compareAndSet(int expect, int update) {
// this为当前对象,valueOffset参数代表了V对象中的变量的偏移量,expect参数代表了A变量预期值,update参数代表了B新的值
// 如果对象this中内存偏移量为valueOffset的变量值为expect,则使用新的值update替换旧的值expect
return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
}
阅读全文 »

分组优化

在使用group by进行分组时,实际上也需要进行排序操作,与order by相比,group by主要是多了排序之后的分组操作

group by的实现有三种方式

  • 使用松散索引扫描实现group by
  • 使用紧凑索引扫描实现group by
  • 使用临时表实现group by
阅读全文 »

开机

BIOS->

启动盘的第一个扇区,512K的大小,称之为MBR(Master Boot Record,主引导记录/扇区),这里保存了boot.img,将之加载到内存中->

boot.img加载grub2的另一个镜像core.img(core.img由diskboot.img、lzma_decompress.img、kernel.img和一系列模块组成)->

diskboot.img的任务是将core.img的其他部分加载进来,显示解压缩程序lzma_decompress.img,然后是kernel.img,最后是各个模块module对应的映像->

lzma_decompress.img实模式到保护模式,建立分段分页,打开地址线->

kernel.img里的grub_main会展示操作系统列表,选择操作系统->

启动内核

RequestBodyAdvice和ResponseBodyAdvice

有两个接口

RequestBodyAdviceResponseBodyAdvice 在spring4中新添加的两个接口

RequestBodyAdvice接口

该接口是在获取@RequestBody参数数据之前进行处理的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public interface RequestBodyAdvice {


boolean supports(MethodParameter methodParameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType);


Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType);


HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException;


Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType);

}

ResponseBodyAdvice接口

该接口是在消息体被HttpMessageConverter消息解析器写入之前执行的

1
2
3
4
5
6
7
8
9
10
11
public interface ResponseBodyAdvice<T> {


boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType);


T beforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType,
ServerHttpRequest request, ServerHttpResponse response);

}