Queue::purgeExpired method (to remove messages from all queues with TTL expired) currently calls Message::hasExpired() method that calls AbsTime::now() i.e. ::clock_gettime for every individual message with TTL set.
That system call is redundant to be called in that way. It is enough to call it once before traversing the very first queue and use the value as an argument.
Proposing a patch (to review also, it's not ideal imho) for that I run a simple performance tests comparison that purged all messages sent there:
- sending 100k transient messages to each of 300 queues: observed 10% performance improvement (improved purge took 740s and original purge took 807s on my virtual box)
- sending 10k durable messages to each of 300 durable queues: observed almost no improvement (improved: 114.48s, original: 115.77s i.e. performance gain in 1.1%) - probably disk operations (common to both tests) kill the improvement; if the test won't purge the messages, (linear)store won't take into pla and improvement would be more visible, I guess