deliveredtechnologies / rulebook

100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL
http://www.deliveredtechnologies.com
Apache License 2.0
716 stars 124 forks source link

Q: RuleBean execution results in full scan? #175

Open willks opened 4 years ago

willks commented 4 years ago

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

Clayton7510 commented 4 years ago

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

Clayton7510 commented 4 years ago

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 commented 4 years ago

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

allenvpn312 commented 4 years ago

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

willks commented 4 years ago

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 commented 4 years ago

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

azell commented 4 years ago

Possible dupe of #155