35 points · by jsnell · 10y ago · 8 comments
AFAICT, the experiments are all single socket. There's an important difference in coherency overhead for single VS multiple sockets; same for futzing with page protection. It also looks like they only tested a single producer/consumer pair. I expect page protection tricks don't scale as nicely when you have 20+ pairs on two sockets: contention on the page table and IPI storms. The mprotect trick also seems to depend on using small (4K) pages, unless you're OK with fairly stale data; probably not ideal for overall app performance.
Also while they indirectly mention the batching trick of the disruptor (keep a reader-local copy of the write index and vice versa), it's not tested… and also not tested with a forced lag between the reader and the writer. If you want to avoid the ping pong, you can let the reader keep a copy of the writer's write pointer (and update the copy when the reader catches up), and artificially make the reader lag behind the writer. That lag gives much simpler code on the hotpath than the MCQueue they mention, which would be the closest equivalent to a laggy disruptor (keeping in mind that the disruptor pattern tends to be used in low latency settings, so that configuration is unlikely to be benchmarked, except indirectly, with cacheline-sized queue items).
It's interesting work, but as is too often the case, the benchmarks give me no actionable information.
(I do agree that they aren't really fairly representing prior work in this area, though, and that nobody optimizing for high performance on commodity hardware is likely to be using 4kb pages).
It's not without drawbacks, relying on handling sigsegv is a pain to make portable (libsigsegv helps!) HotSpot handles sigsegv, but I think it's possible to install your own handler as well by setting it before loading the JVM. When the JVM loads it will chain pre-existing signal handlers behind its own, and they'll be invoked if the signal doesn't pertain to HotSpot. LD_PRELOAD can be used to accomplish that. My information may only apply to an older version of HotSpot though, I don't know if that's still the case.
The other thing is relying on the TLB here becomes trickier with huge pages. It seems to me that the section and queue boundary trap pages are set just once at queue init and then never changed - so one could do the same with 2mb huge pages, without wasting memory, if the sections are sufficiently large. The problem is that requires the producer and consumer to be at least 2mb of queue apart, which is probably too much delay for many applications where latency is important. But I really don't see the need for huge pages here. A queue where both producer and consumer are repeatedly touching the same page seems like the ideal use case for the TLB anyway.
Not all applications can tolerate a sectioned queue though, for example what happens when the producer writes less than a full section of items to the queue and then pauses for a long time? The consumer won't be able to access that data until the producer finishes the section.
Is there any effect due to virtualization?