Should I use Drools in this situation?

后端 未结 5 1714
难免孤独
难免孤独 2021-02-08 19:11

I\'ll use a university\'s library system to explain my use case. Students register in the library system and provide their profile: gender, age, department, previously completed

5条回答
  •  -上瘾入骨i
    2021-02-08 20:02

    My questions are: how much memory will Drools take if loaded with a million book rules? How fast will it be for all those million rules to fire?

    How fast is your computer and how much memory have you got? In one sense you can only find out by building a proof of concept and filling it with the right quantity of (randomly-generated) test data. My experience is that Drools is faster than you expect, and that you have to have very good knowledge of what's under the hood to be able to predict what is going to make it slow.

    Note that you are talking about a million rule session facts (i.e. Book objects), not a million rules. There are only a handful of rules, which won't take long to fire. The potentially slow part is inserting the million objects, because Drools needs to decide which rules to put on the Agenda for each new fact.

    It's a shame that none of us has an answer for some particular set-up with a million facts.

    As for the implementation, my approach would be to insert a Book object for each book that the student wants to check out, retract the ones that are not allowed, and a query to get the remaining (allowed) Book objects, and another query to get the list of reasons. Alternatively, use RequestedBook objects that have additional boolean allowed and String reasonDisallowed properties that you can set in your rules.

提交回复
热议问题