[Java] Observability for ThreadPoolFory
Feature Request
It would be great if it was possible to monitor ThreadPoolFory in some way.
Our production profiler shows that more Fory instances are created over time than I would expect, but we currently have no way to see what is going on. At the very least, ThreadPoolFory should have debug logs when new instances are created and for which ClassLoader. Ideally, we would have additional statistics for the pool: the current size, the peak size etc.
Is your feature request related to a problem? Please describe
No response
Describe the solution you'd like
No response
Describe alternatives you've considered
No response
Additional context
The only log output currently generated that can detect a new Fory instance being created is this quite unhelpful one:
org.apache.fory.Fory : Created new fory org.apache.fory.Fory@50e383c
This can definitely be improved by implementing a meaningful toString implementation that contains the name of the instance if set, potentially the class-loader, etc.
Sounds great, would you like to create a pr?
I don't have time to work on full observability at the moment, but I might be able to create a PR to improve the current log output.
is this issue to someone? if not could you please assign it to me! My background - I am currently a working professional and i have the knowledge of the techstack used and would like to contribute...
I'm not planning on working on this at the moment. What I'm currently doing is reflecting into ThreadPoolFory and creating the following metrics:
final ForyPooledObjectFactory objectFactory = (ForyPooledObjectFactory) ReflectionUtil.readField(fory, "foryPooledObjectFactory");
Metrics.gauge("fory.cache.numIdle", Tags.of("name", name), objectFactory, value -> {
final ClassLoaderForyPooled c = value.getPooledCache();
return ((BlockingQueue<?>) ReflectionUtil.readField(c, "idleCacheQueue")).size();
});
Metrics.gauge("fory.cache.numActive", Tags.of("name", name), objectFactory, value -> {
final ClassLoaderForyPooled c = value.getPooledCache();
return ((AtomicInteger) ReflectionUtil.readField(c, "activeCacheNumber")).get();
});
Metrics.gauge("fory.cache.numAll", Tags.of("name", name), objectFactory, value -> {
final ClassLoaderForyPooled c = value.getPooledCache();
return ((Map<?, ?>) ReflectionUtil.readField(c, "allFory")).size();
});
Since numAll is always the same as numActive it should be enough to expose metrics for numIdle and numActive. Ideally, ThreadPoolFory would expose a method like getPoolStats() that gives the user access to these metrics.
@chaokunyang What do you think?
Yes, expose a getPoolStats API would be great. @JaskaranSingh-01 Would you like to work on this?
yes, that would be great!! how do i get started?
yes, that would be great!! how do i get started?
@JaskaranSingh-01 You can follow https://github.com/apache/fory/blob/main/CONTRIBUTING.md and submit a PR
Hi @chaokunyang , I’d like to work on this issue. Could you please assign it to me? Thank you!
Hi @chaokunyang , I’d like to work on this issue. Could you please assign it to me? Thank you!
Great! Assigned to you
Thanks a lot for assigning this to me! I’ll get started and keep you updated on my progress.