Make jvm_memory_direct_bytes_used metrics compatible with jdk8. - #3677
Conversation
hezhangjian
left a comment
There was a problem hiding this comment.
Should we add another test case or just modify it?
Already change the test case to cover it. |
|
rerun failure checks |
| private static final Optional<BufferPoolMXBean> poolMxBeanOp; | ||
|
|
||
| static { | ||
| AtomicLong tmpDirectMemoryUsage = null; |
There was a problem hiding this comment.
Do we need to get direct memory usage here according to PlatformDependent.useDirectBufferNoCleaner() here instead of getting both values?
|
rerun failure checks |
1 similar comment
|
rerun failure checks |
|
rerun failure checks |
| List<BufferPoolMXBean> platformMXBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class); | ||
| poolMxBeanOp = platformMXBeans.stream() | ||
| .filter(bufferPoolMXBean -> bufferPoolMXBean.getName().equals("direct")).findAny(); | ||
| getDirectMemoryUsage = () -> poolMxBeanOp.get().getMemoryUsed(); |
There was a problem hiding this comment.
We need to check whether poolMxBeanOp is present before get
| log.warn("Failed to access netty DIRECT_MEMORY_COUNTER field {}", t.getMessage()); | ||
| } | ||
| directMemoryUsage = tmpDirectMemoryUsage; | ||
| getDirectMemoryUsage = () -> directMemoryUsage.get(); |
There was a problem hiding this comment.
We need to check whether the directMemoryUsage is null before get
| */ | ||
| private static AtomicLong directMemoryUsage; | ||
| private static Optional<BufferPoolMXBean> poolMxBeanOp; | ||
| private static Supplier<Long> getDirectMemoryUsage; |
|
ping @eolivelli @dlg99 @zymap @shoothzj, please help take a look, thanks. |
# Conflicts: # stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/main/java/org/apache/bookkeeper/stats/prometheus/PrometheusMetricsProvider.java
|
rerun failure checks |
| poolMxBeanOp = Optional.empty(); | ||
| AtomicLong tmpDirectMemoryUsage = null; | ||
| try { | ||
| Field field = PlatformDependent.class.getDeclaredField("DIRECT_MEMORY_COUNTER"); |
There was a problem hiding this comment.
Looks like they have the usedDirectMemory() method to access that field. Why don't we use that?
) (cherry picked from commit 5a38080)
…ache#3677) (cherry picked from commit 5a38080) (cherry picked from commit f73c7a1)
Descriptions of the changes in this PR: ### Motivation Fix cherry-pick apache#3677 issue (cherry picked from commit b454014)
) (cherry picked from commit 5a38080)
Descriptions of the changes in this PR:
In #3252, it only uses poolMxBeanOp to get direct memory usage. It only works in jdk11.
But if the user still uses the old version, netty still uses
NoCleanerConstructorByteBuffer to allocate direct memory, the poolMxBeanOp didn't cover it.We should check the netty
PlatformDependent.useDirectBufferNoCleaner(), then choose the corresponding way to get direct memory usage.