There is a problem with my Java program. I checked it with top and found that the RSS resource is much larger than the maximum value of the heap memory. here is my code,very simple
@RequestMapping("/test")
public Mono<BridgeResopnse> test(@RequestParam("num") Integer num, @RequestParam("size") Integer size) {
log.info("PlatformDependent.usedDirectMemory(): {} MB", PlatformDependent.usedDirectMemory() / 1024 / 1024);
return Mono.fromCallable(() -> {
BridgeResopnse bridgeResopnse = new BridgeResopnse();
bridgeResopnse.setContent(getContent(num, size));
bridgeResopnse.setCrc("crc");
return bridgeResopnse;
});
}
private static String getContent(int num, int size) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < num; i++) {
sb.append(RandomUtil.randomString(size)).append(";\n");
}
return sb.toString();
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BridgeResopnse {
String content;
String crc;
}
here is my java config: java -Xms512m -Xmx512m -XX:+UseG1GC -jar demo.jar jdk: jdk1.8.0_151 netty-core: 4.1.94.Final here is my Stress test settings and rss
/test?num=1000&size=2400 ,return response size is 2.29mb
enter image description here enter image description here
In addition, when I increase the amount of data returned, it may cause OutOfDirectMemoryError. At this time, the log reports an error. This is normal, but the RSS is also increasing at this time, and as the stress test stops, the RSS will be very large. Please see the figure below. here is my Stress test settings and rss
/test?num=1000&size=5000 ,return response size is 4.77mb