leak(一)
0
服务对外内存oom,但健康检测还能访问,因为健康检测走8081直接,走的jvm内存
1 使用netty自带的泄露参数 -Dio.netty.leakDetectionLevel=advanced
https://zhuanlan.zhihu.com/p/624117573?utm_id=0
30000 https网关,20000为http代理-》8081
反复访问https://localhost:30000
2 压力测试直到OOM
2.1 初始给10k -XX:MaxDirectMemorySize=10k
警告: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16384 byte(s) of direct memory (used: 1031, max: 10240)
2.2 给100k
压力代码:
package com.jds.test.httpproxy.miniserver; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.impl.client.CloseableHttpClient; import java.io.IOException; /** * Created by mac on 2024/4/6. */ public class Test { public static void main(String []f) { for(int i=0; i<200; ++i) { main0(i); } } public static void main0(int f) { CloseableHttpClient httpClient = null; try { HttpRequestBase httpUriRequest = null; httpClient = HttpServerJob.HttpClientFactory.createSSLClientDefault(null, null); httpUriRequest = new HttpGet("https://localhost:30000"); RequestConfig.Builder builder = RequestConfig.custom(); builder.setRedirectsEnabled(false).setConnectTimeout(10000).setSocketTimeout(100000); httpUriRequest.setConfig(builder.build()); CloseableHttpResponse response = httpClient.execute(httpUriRequest); int ret = response.getStatusLine().getStatusCode(); System.out.println(f+""+ret); } catch (Exception e) { e.printStackTrace(); } finally { if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
第15个请求挂了
这个文件大小为6k,6*14=84
四月 07, 2024 12:19:00 上午 io.netty.channel.DefaultChannelPipeline onUnhandledInboundException
警告: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 3840 byte(s) of direct memory (used: 98567, max: 102400)
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
scheduledExecutorService.scheduleAtFixedRate(()->{
System.out.println("used direct memory: " + PlatformDependent.usedDirectMemory());
}, 1, 1, TimeUnit.SECONDS);
used direct memory: 0
used direct memory: 37029
used direct memory: 98311
used direct memory: 98311
used direct memory: 98311
used direct memory: 98311
2.3 after
200个完成
used direct memory: 0
used direct memory: 2130
used direct memory: 2213
used direct memory: 2213
used direct memory: 2213
used direct memory: 2213
used direct memory: 7
used direct memory: 7
used direct memory: 7
used direct memory: 7
used direct memory: 7
2.4 windows (java11)下100k 2000个请求都没问题,只是提示有leak,usedDirectMemory=-1, 而且MaxDirectMemorySize是设置成功的,因为可以复现2.1
3 原服务压测BC AC
3.1 BC
考虑一个js,大小为949k,uat对外内存为2G,2*1024*1024/949=about2000,
也就是说2000次请求后,uat应该挂掉
结果没挂。。
3.2 AC
/