是否有可能/合理地使用OpenJ9 9的类共享特性来减少不同应用程序的单个实例的内存使用?
更多详细信息:
在同一台机器上运行同一应用程序的多个实例(例如Kubernetes节点)时,该特性似乎是为了减少内存使用。对吗?
我想要实现的是,碰巧在同一个Kubernetes节点上启动的应用程序使用相同的缓存。由于应用程序使用的是几乎相同的库,所以应该有大量可以共享的数据。然而,我所经历的是缓存率很高的陈旧类,甚至缓存变得100%满,即使我使用软和硬限制1GB。
具体来说,我尝试在同一个Kubernetes节点上使用java -Xshareclasses:cacheDir=/openj9cache,groupAccess,name=somename,nonfatal,persistent,verbose -XX:SharedCacheHardLimit=1g -Xscmx1g <APP>进行不同的部署。根据我运行的应用程序,我看到缓存统计信息如下:
cache layer = 0
cache size = 1073741216
softmx bytes = 1073741824
free bytes = 0
Reserved space for AOT bytes = -1
Maximum space for AOT bytes = -1
Reserved space for JIT data bytes = -1
Maximum space for JIT data bytes = -1
Metadata bytes = 937848376
Metadata % used = 87%
Class debug area size = 85868544
Class debug area used bytes = 4246022
Class debug area % used = 4%
ROMClass bytes = 36481772
AOT bytes = 12671632
JIT data bytes = 506596
Zip cache bytes = 0
Startup hint bytes = 360
Data bytes = 363936
# ROMClasses = 45685
# AOT Methods = 2997
# Classpaths = 30076
# URLs = 0
# Tokens = 0
# Zip caches = 0
# Startup hints = 3
# Stale classes = 40496
% Stale classes = 88%
Cache is 100% soft fullcache layer = 0
cache size = 1073741216
softmx bytes = 1073741824
free bytes = 0
Reserved space for AOT bytes = -1
Maximum space for AOT bytes = -1
Reserved space for JIT data bytes = -1
Maximum space for JIT data bytes = -1
Metadata bytes = 935010252
Metadata % used = 87%
Class debug area size = 85868544
Class debug area used bytes = 4745600
Class debug area % used = 5%
ROMClass bytes = 40151980
AOT bytes = 11919936
JIT data bytes = 426448
Zip cache bytes = 0
Startup hint bytes = 120
Data bytes = 363936
# ROMClasses = 38554
# AOT Methods = 2950
# Classpaths = 22680
# URLs = 0
# Tokens = 0
# Zip caches = 0
# Startup hints = 1
# Stale classes = 6354
% Stale classes = 16%
Cache is 100% soft fullbase address = 0x00007F3D8C059000
end address = 0x00007F3DCC000000
allocation pointer = 0x00007F3D8F10BB80
cache layer = 0
cache size = 1073741216
softmx bytes = 1073741824
free bytes = 706740256
Reserved space for AOT bytes = -1
Maximum space for AOT bytes = -1
Reserved space for JIT data bytes = -1
Maximum space for JIT data bytes = -1
Metadata bytes = 199367772
Metadata % used = 54%
Class debug area size = 85868544
Class debug area used bytes = 6499570
Class debug area % used = 7%
ROMClass bytes = 51063680
AOT bytes = 29461056
JIT data bytes = 875612
Zip cache bytes = 0
Startup hint bytes = 360
Data bytes = 363936
# ROMClasses = 30778
# AOT Methods = 6624
# Classpaths = 8349
# URLs = 0
# Tokens = 0
# Zip caches = 0
# Startup hints = 3
# Stale classes = 3274
% Stale classes = 10%
Cache is 34% soft full发布于 2020-09-08 16:18:29
对同一(或类似)应用程序的多个实例使用相同的共享缓存是最佳做法。如果您在不同的应用程序之间共享相同的缓存,则可能无法节省(大部分)内存,因为共享缓存包含由当前应用程序不需要的其他应用程序存储的类。
OpenJ9正在对类路径上的jars进行时间戳检查。它确保类路径上的类没有更新,因为它存储在缓存中,因此我们可以安全地将缓存的类返回给类加载器。一旦找到更新,原始缓存类将被标记为“陈旧”。
使用子选项"bootClassesOnly“只为引导类打开类共享。没有人在引导类路径上更新东西,所以您不会看到陈旧的类。
我看到缓存统计中有数千个类路径。这些类路径上的内容是更新的还是在运行时生成的?您可以使用-Xshareclasses子选项"printStats=classpath“显示所有类路径。如果您确信类在运行期间没有更新,则可以使用-Xshareclasses子选项"noTimestampChecks“关闭时间戳检查。
https://stackoverflow.com/questions/63776456
复制相似问题