Use of the first level cache in the DieruptorRepository

Hello, everyone! We are using Axon 2.4.5 in production and are also using the DisruptorCommandBus to act as the local segment. Noticed that the CommandHandlerInvoker$DisruptorRepository makes use of a WeakHashMap as the first level cache. We run all our JVM instances with 2GB of heap. We have a process that creates a large number of aggregates (approximately 3 million) as part of an import job.

Specifically, the load method in the DisruptorRepository piqued our interest:

It appears we do a linear search on the first level cache to locate the cached aggregate. When there is no memory pressure, this linear search can take quite a while (in relative terms). This slows things down considerably. We noticed that the DisruptorRepository’s firstLevelCache is not very easily accessible. Changing behavior there, for e.g. disabling the first level cache requires overriding framework which we’re reluctant to do. It appears this part hasn’t changed much in the 3.0 release as well.

Can you please advise?

Hi Prem,

the primary reason for the “first level cache” isn’t performance, but ensuring changes are performed against the correct aggregate state. If two commands arrive for the same aggregate, you want the second command to be executed against the state left by the first.
If you have any suggestions for improving this cache, they’re welcome! I’m a bit reluctant to make this configurable, as it complicates APIs even more.