rulebook icon indicating copy to clipboard operation
rulebook copied to clipboard

Q: RuleBean execution results in full scan?

Open willks opened this issue 5 years ago • 7 comments

Hi, Just a small question - but does every invocation of "SpringAwareRuleBookRunner" result in a full package scan? These are the logs I am seeing:

2019-12-19 13:24:13.589  INFO 15322 --- [atcher-worker-2] org.reflections.Reflections              : Reflections took 3 ms to scan 1 urls, producing 4 keys and 9 values 
2019-12-19 13:25:48.746  INFO 15322 --- [atcher-worker-7] org.reflections.Reflections              : Reflections took 2 ms to scan 1 urls, producing 4 keys and 9 values 
2019-12-19 13:26:37.353  INFO 15322 --- [atcher-worker-3] org.reflections.Reflections              : Reflections took 3 ms to scan 1 urls, producing 4 keys and 9 values 
2019-12-19 13:30:10.100  INFO 15322 --- [atcher-worker-2] org.reflections.Reflections              : Reflections took 2 ms to scan 1 urls, producing 4 keys and 9 values 
2019-12-19 13:31:39.640  INFO 15322 --- [atcher-worker-5] org.reflections.Reflections              : Reflections took 2 ms to scan 1 urls, producing 4 keys and 9 values 
2019-12-19 13:31:39.926  INFO 15322 --- [atcher-worker-8] org.reflections.Reflections              : Reflections took 3 ms to scan 1 urls, producing 4 keys and 9 values 
2019-12-19 13:32:26.740  INFO 15322 --- [atcher-worker-4] org.reflections.Reflections              : Reflections took 2 ms to scan 1 urls, producing 4 keys and 9 values 
2019-12-19 13:32:53.214  INFO 15322 --- [atcher-worker-1] org.reflections.Reflections              : Reflections took 2 ms to scan 1 urls, producing 4 keys and 9 values 
2019-12-19 13:35:38.264  INFO 15322 --- [atcher-worker-2] org.reflections.Reflections              : Reflections took 2 ms to scan 1 urls, producing 4 keys and 9 values 

Just a question.

Thanks for a nice framework for rules

willks avatar Dec 19 '19 13:12 willks

Yes, it does. This is done for thread safety. Although, perhaps there is a more elegant way to solve the problem.

Clayton7510 avatar Jan 22 '20 21:01 Clayton7510

I'm looking into switching this to a single scan. But the instantiation of the POJOs that are found in the scan will still take place on every run and there is a little reflection involved there since it transforms a POJO class representation into a Rule via an adapter.

Clayton7510 avatar Feb 04 '20 00:02 Clayton7510

There is an update in 0.12-SNAPSHOT that has a fix for this.

Clayton7510 avatar Feb 04 '20 01:02 Clayton7510

@Clayton7510 is there a way to turn off scan logging?

allenvpn312 avatar Feb 20 '20 20:02 allenvpn312

Sorry I didn't post this earlier. I worked around it before the 0.12-SNAPSHOT was posted. This is my code in Kotlin for setting up my rules. They have to be added in order of execution:

        val pojoRules = listOf<Class<*>>(
                EmptyPayloadRule::class.java,
                ValidJsonRule::class.java,
                TemperatureDeviceRule::class.java,
                UnknownRule::class.java)
        return RuleBookRunner4PojoClasses(pojoRules) as RuleBook<MyReturnEntityType>

This will avoid full scans, but the onus is on setting up order properly. Everything worked well. We're running these rules potentially hundreds/thousands of times per second through Kotlin Coroutines. It's held up well.

As a side note - this framework has been awesome for us. It allowed us to remove business rules into small, distinct, clear rules that are easy to update. The rest of our code is just calling out to these rules. I have smashed it with hundreds of threads simulating thousands of concurrent users. Didn't skip a beat!

One of my favourite projects on Github by far. Good work has been done here, much appreciated.

Thanks

willks avatar Feb 28 '20 11:02 willks

@Clayton7510 With all that said, I found a work-around. I think we can close this issue out from my perspective.

willks avatar Feb 28 '20 12:02 willks

Possible dupe of #155

azell avatar Apr 21 '20 04:04 azell