Live data from Hacker News

84% of a single-threaded 1KB write in Redis is spent in the kernel

blog.nullspace.io

41–50 of 51 posts

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#41

I am not very familiar with OSes and things at the kernel level, can anyone answer the question in the comments of the post? "How did you measure the time spent in each section (HW, kernel, app)? how did you get such granularity?"

From the Arrakis paper: "To analyze the sources of overhead, we record timestamps at various stages of kernel and user-space processing." You can probably implement this with something like perf dynamic tracing: http://www.brendangregg.com/perf.html#DynamicTracing

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#42
post #37
post #24

To be clear, 80% of kernel-time in that 1KB write is spent in fsync(), _not_ in the network stack. Network overhead is roughly similar between read & write requests. What Arrakis seems to be able to do is avoid the overhead of write & sync, presumably because it doesn't go through the VFS + filesystem + block IO code paths.

>To be clear, 80% of kernel-time in that 1KB write is spent in fsync(), _not_ in the network stack Are you sure? Of the total 3.36 μs (see Table 1) spent processing each packet in Linux, nearly 70% is spent in the network stack

Table 1 is looking specifically at getting a chunk of data off the wire and into the users code. Look at Table 2 for a comparison of redis read/write. Average time for a write is 163 μs - of which 137 μs is spent in fsync(2)

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#43
post #42
post #37

Earlier quoted context omitted.

>To be clear, 80% of kernel-time in that 1KB write is spent in fsync(), _not_ in the network stack Are you sure? Of the total 3.36 μs (see Table 1) spent processing each packet in Linux, nearly 70% is spent in the network stack

Table 1 is looking specifically at getting a chunk of data off the wire and into the users code. Look at Table 2 for a comparison of redis read/write. Average time for a write is 163 μs - of which 137 μs is spent in fsync(2)

[deleted]

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#44
post #42
post #37

Earlier quoted context omitted.

>To be clear, 80% of kernel-time in that 1KB write is spent in fsync(), _not_ in the network stack Are you sure? Of the total 3.36 μs (see Table 1) spent processing each packet in Linux, nearly 70% is spent in the network stack

Table 1 is looking specifically at getting a chunk of data off the wire and into the users code. Look at Table 2 for a comparison of redis read/write. Average time for a write is 163 μs - of which 137 μs is spent in fsync(2)

Right but you can't compare table 2 data to the network stack, table 2 data is only timing the redis operations. Which as stated take up significantly less time than the time spent in the network stack.

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#45

This is why high-performance commercial databases do most or all of their I/O management and scheduling in userspace. It is not a new idea; it is much more efficient. However, that means you need to reimplement most of what the kernel does in an optimal way. This is relatively common for closed source software but you almost never see these types of userspace I/O designs in open source, which means OSS designs are of…

Indeed. Oracle basically uses the OS just to bootstrap itself and hand over the initial chunk of memory, then it manages everything internally. It even talks to NFS itself rather than going through VFS. Opens a socket from userland code to the NetApp and reads and writes the raw protocol.

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#46
post #12

The concept of redis has always baffled me. A hash table is a very fast data structure. As soon as you put that in a dedicated server, the cost of the actual lookup is instantly eclipsed by the need to parse a text protocol and do network I/O to communicate with the client. So I'd be willing to say that the problem here isn't that the kernel stack is slow per-se, but that workload is too small as to make the overhead…

Let's say you have a 8gb hash table that you want shared between 32 app servers. You are only setting or getting a few elements each request.

It doesn't make sense for each app server to have an 8gb hash table in their memory nor can they easily be synchronized.

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#47

Earlier quoted context omitted.

Having worked on an embedded system that dealt primarily with network I/O (10 Gbps) and hash tables (in the 10 GiB range), I can tell you that network I/O (done right!) and parsing account for MAYBE 1/3 of the total latency of an operation involving a hash table lookup. Memory, like all mass storage, is SLOW once you're not working in cache, and hash tables have no locality. (By "done right!" I mean either batching r…

I've no doubt memory is slow, taking up to 100-300 cycles in NUMA systems. But a single threaded server accessing local memory won't may those costs as much. Are you saying that a few random memory accesses are slower than sending and receiving a packet on two machines? Redis has a great position as a persistent, shareable, data structure server, but replacing in memory hashtables where they work doesn't seem like on…

Sure... on a 10 Gbps link, you can transfer up to 15 million packets per second (assuming a tiny payload... which is about all you need for a hash lookup). That's about the same order of magnitude as the latency of a single memory lookup that misses the cache. In the right environment (not TCP on a stock Linux kernel!) each packet carries very little CPU overhead.

Of course, you can pipeline memory accesses to some degree, but not as easily as you can aggregate network requests into fewer packets.

I'm certainly not saying the network overhead is free -- it's not! I'm just saying it needn't "eclipse" the hash table lookup itself (as the GP suggested). They're on the same order of magnitude.

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#48
post #12

The concept of redis has always baffled me. A hash table is a very fast data structure. As soon as you put that in a dedicated server, the cost of the actual lookup is instantly eclipsed by the need to parse a text protocol and do network I/O to communicate with the client. So I'd be willing to say that the problem here isn't that the kernel stack is slow per-se, but that workload is too small as to make the overhead…

But if you do it right you don't parse anything, you take a chunk of bytes off the wire and just cast them to a struct, which you know because you defined the protocol in the first place. This is how market data systems do it.

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#49
post #21
post #12

The concept of redis has always baffled me. A hash table is a very fast data structure. As soon as you put that in a dedicated server, the cost of the actual lookup is instantly eclipsed by the need to parse a text protocol and do network I/O to communicate with the client. So I'd be willing to say that the problem here isn't that the kernel stack is slow per-se, but that workload is too small as to make the overhead…

There's two groups of people who need to squeeze all the work out of every cycle they can get: Embedded programmers (which, despite our massively powerful phone processors, still includes mobile due to power issues), and cloud programmers. Cloud people are totally interested in optimizing everything to within an inch of its life, so it's a valid concern for them that even if they reduce their user space costs to 0 th…

And HPC guys, and HFT guys, and graphics guys... Cloud schmoud.

Re: 84% of a single-threaded 1KB write in Redis is spent in the kernel

#50

I wonder if anyone has tried it with Solarflare?

Solarflare has a whitepaper on accelerating memcached: http://10gbe.blogspot.com/2014/12/memcached-3x-faster-than-i... I just whipped this up in 5 minutes and didn't do much of the tuning there (e.g. no isolcpus or interrupt changes), but here's a single-client 1024-byte SET redis-benchmark running against localhost with and without TCP Loopback Acceleration... redis 2.8.4 on a dual E5-2630 @ 2.30GHz, card is SFN5122…

Not bad considering its "for free". Thanks a lot for the post
Post reply on HN