zuul 参数调优 适用版本: spring-boot: 1.4.x.RELEASE spring-cloud:Camden.SR3 Hystrix: 1.5.6 spring-boot-tomcat 优化参数: 主要只有2个,最大和最小worker线程: 1 2 server.tomcat.max-threads=128 # Maximum amount of worker threads. server.tomcat.min-spare-threads=64 # Minimum amount of worker threads. spring-boot-undertow 优化参数: ioThreads 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接,默认取CPU核心数量,最小值为2。 Math.max(Runtime.getRuntime().availableProcessors(), 2); spring-boot 参数:server.undertow.io-threads= worker-threads 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载,默认值为io-threads*8。 spring-boot 参数:server.undertow.worker-threads= buffer buffer-size: 每块buffer的空间大小,越小的空间被利用越充分。 **buffers-per-region: ** 每个区分配的buffer数量 , 所以pool的大小是buffer-size * buffers-per-region。 directBuffers 是否分配的直接内存。 获取JVM最大可用内存maxMemory=...
RestTemplate遇上Hystrix RestTemplate集成Hystrix和Robbin 查看RestTemplate源代码,可以看到RestTemplate继承了InterceptingHttpAccessor类,InterceptingHttpAccessor类通过ClientHttpRequestInterceptor接口提供了扩展功能。 实现intercept方法,在该方法中封装HystrixCommand和Ribbon逻辑即可。 下面的代码是集成了HystrixCommand的例子: 1 2 3 4 5 6 7 8 9 10 11 12 13 @Override public ClientHttpResponse intercept( final HttpRequest request, final byte[] body, final ClientHttpRequestExecution execution) throws IOException { final URI originalUri = request.getURI(); String serviceName = mapCommandKey(originalUri); log.info("{} :{} {} ", serviceName, request.getMethod().name(), originalUri.toString()); return new RestTemplateHystrixCommnad(serviceName, () -> { return execution.execute(request, body); }, hystrixFallback).execute(); } 下面是集成了HystrixCommand和Ribbon的例子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @Override public ClientHttpResponse intercept( final HttpRequest request, final byte[] body, final ClientHttpRequestExecution execution) throws IOException { final URI originalUri = request.getURI(); String serviceName = mapCommandKey(originalUri); log.info("{} :{} {} ", serviceName, request.getMethod().name(), originalUri.toString()); return new RestTemplateHystrixCommnad(serviceName, () -> { return this.loadBalancer.execute(serviceName, instance -> { HttpRequest...
git https://github.com/wg/wrk git clone https://github.com/wg/wrk.git 安装 在makefile中33行 LDIR = deps/luajit/src LIBS := -lluajit $(LIBS) CFLAGS += -I$(LDIR) LDFLAGS += -L$(LDIR) 下面添加: LDFLAGS += -L/usr/local/opt/openssl/lib CFLAGS += -I/usr/local/opt/openssl/include make 基本使用 Basic Usage wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html This runs a benchmark for 30 seconds, using 12 threads, and keeping 400 HTTP connections open. Output: 1 2 3 4 5 6 7 8 Running 30s test @ http://127.0.0.1:8080/index.html 12 threads and 400 connections Thread Stats Avg Stdev Max +/- Stdev Latency 635.91us 0.89ms 12.92ms 93.69% Req/Sec 56.20k 8.07k 62.00k 86.54% 22464657 requests in 30.00s, 17.76GB read Requests/sec: 748868.53 Transfer/sec: 606.33MB 参数说明 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 $ wrk Usage: wrk <options> <url> Options: -c, --connections <N> Connections to keep open -d, --duration <T> Duration of test -t, --threads <N> Number of threads to use -s, --script <S> Load Lua script file -H, --header <H> Add header to request --latency Print latency statistics --timeout <T> Socket/request timeout -v, --version Print version details Numeric arguments may include a SI unit (1k, 1M, 1G) Time arguments may include a time unit (2s, 2m, 2h)...