Comments (4)
Would it be possible the share that example script?
Reading the javadoc, I was under the impression that getThreadAllocatedBytes() would return the amount of allocated memory for that thread, taking into account any changes (and thus not simply counting up). However, from your observations it seems like that's not the case.
from flowable-engine.
ThreadMXBean does provide the currently allocated memory of the thread correctly yes.
But, because the jvm uses GC to clean up allocated objects, the “allocated” value is inflated because it contains objects that would be freed by GC.
If there is enough free heap available for the jvm, it will not run GC at all (or not aggressively, also depending on the chosen GC algorithm and the configuration for it). Thus, the value reported by threadmxbean is technically correct but does not reflect reality, a script can create 100s of megabytes of objects that it no longer references, but before garbage collection is ran, those show up as allocated memory.
I will try to build a small sample testcase to show this behavior.
from flowable-engine.
Thanks for the explanation, that clarifies it.
And besides manually allowing to trigger GC (which is not a guarantee) I indeed don't see an immediate solution to this, as it would require to "look if memory is deemed free-able" or to release memory, which is impossible on the JDK platform.
No need for an example, it's clear, unless you see a potential solution to this?
from flowable-engine.
Yes, manually triggering GC is not a fix (and as you said, nothing guarantees it will happen immediately, or at all).
I have no immediate solution to this either, some ideas, but neither of these is really reliable / do what the current implementation claims to do:
-
keep track of allocation rate and provide a configurable limit to this
- by keeping track of when observeInstructionCount was last called, one could use getThreadAllocatedBytes to calculate a "bytes allocated per second" value, which would be somewhat meaningful even when GC is not executed
- trying to find suitable limits for this value would be rather difficult
- probably would need to keep some kind of a rolling average for any limit enforcing to make any sense
-
keep some sort of "Heap memory pressure" value available at all times and only enforce the "max memory used" value when X percent (configurable) of Heap memory has been used (average) for the last Y seconds (configurable)
- so if 95% of heap has been in use for the last 5 seconds, the getThreadAllocatedBytes for the thread executing a script would be more like to be a sensible value ,as it would be expected for the JVM to attempt to perform GC as much as it can when Heap is running low
- probably still not reliable, but possibly "good enough"
- tricky to implement correctly
Flowable is not the only Rhino sandbox using the exact same logic to limit memory for a script, but none of them seem to actually take GC into account at all..
from flowable-engine.
Related Issues (20)
- realease6.8.1 has a bug ,because The rollback Cannot roll back correctly in the case of multiple instances,please fix soon HOT 1
- flowable-ui的版本和flowable-engine的版本不太一致
- Delay in seconds before script condition executed HOT 6
- task complete before report NoSuchMethodError: org.flowable.bpmn.model.UserTask.getTaskCompleterVariableName() , flowable version: 7.0.1 HOT 2
- Flowable 7.0.1 not getting installed in ecliupse HOT 1
- Conditions should support more than JUEL expressions
- suspendProcessInstanceById question
- BpmnXMLUtil.parseExtensionElement setElementText has bug of Line wrap cover HOT 1
- Process migration cannot migrate processes HOT 1
- Process definition id of an async external worker service task job is not updated after direct migration HOT 2
- 是否有审批人驳回到上级,上级修改后在发起继续审批流程 HOT 1
- Invalid SQL upgrade scripts for HSQL database (7.0.0 -> 7.0.1)
- The DefaultIdentityLinkIterceptor.java creates duplicate identityLinks on ProcessInstance
- AsyncTaskInvokerTaskExecutor supplied by Spring Boot autoconfiguration is not started
- Not possible to exclude the `flowable-event-registry` JAR even if EventRegistry disabled
- startProcessInstanceByKey does not always trigger the process HOT 3
- Liquibase first up does not work with JtaProcessEngineConfiguration HOT 1
- Timer job never unlocked after an exception
- Query the sorting exception of HistoricActivityInstance
- After running runtimeService().deleteProcessInstance(processInstance.getId()) to delete the parent process instance, the CallActivity subprocessInstance query is null HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flowable-engine.