Hacker News new | ask | show | jobs
by kqueue 5341 days ago
Network IO, Disk IO, scheduling, locks etc.. all trigger context switches and not only mode switch because only the kernel is allowed to manipulate data structures related to mbufs, vfs, and whatnot.

When I said epoll/kqueue doesn't affect the accept rate, I was replying back to a specific request of writing a program to just accept/reply/shutdown. In this case you are passing one fd to the poller which won't matter much what poller you are using.

My original comment is that you are measuring the wrong thing and it's not against hellepoll. requests / sec can be much higher than reply / sec because they get buffered waiting for you to accept them. Once accepted, then a request is counted. What matters though, especially to the http client is how long it takes to serve the connection from start to finish, hence reply rate.

fyi, you can use libev for poller portability.

You can experiment with this command and look at the reply rate.

httperf --num-conns=10000000 -vv --num-calls=1 --port=<your_port>

1 comments

1) yes I've used libevent and libev and others in the past

2) ab does wait for the requests to complete before sending the next

3) you really are flat wrong when you don't make a distinction between mode switching and context switching

4) conclusion: with a name like yours, you must be trolling

I didn't say there is no distinction. I said system calls that require disk io, or network io, or triggers locking/sleeping requires a context switch. Calls like read/write/accept triggers context switches (which starts with a mode switch). The switch is required for the kernel to execute the system calls and operate on it's own data structures. Only the kernel can alter mbufs in this case.

Go read your OS book.

I am not trolling. you just lack experience and this sounds new to you.

Thank you for making me challenge my assumptions and memory.

I've asked around a bit and am fairly sure of my facts again, and my understanding is:

* kernel mode is cheaper than ever to reach; SYSCALL/SYSENTER etc so its not even an interrupt and there are no hardware threads or anything involved

* in kernel mode, the thread can get straight at the buffer and the locks that protect it; there is nothing that we'd call a 'context switch' in there

* being as this seems to be what is meant by monolithic kernel, surely its the same on freebsd too?

I totally agree that SYSCALL/SYSENTER/SYSRET are very cheap to execute. But these instructions only takes care of the ring switch and are not executed alone.

When you make a system call, a trap is issued that causes the hardware switch to kernel mode.

The hardware pushes onto the per-process kernel stack the pc, status word, and the kernel code takes care of saving the registers, esp, etc.. this is called a task context switch. Context switching between processes is much more expensive but task context switching is still considered a context switch.

When you are making a system call, it's still much more expensive then most of the work you are doing in your program hellepoll and hence it's your bottleneck. This is why you don't see your process's CPU at 100%.

On a related note, whenever you have a program doing a lot of network IO, you are essentially causing a lot of process context switches because each time you get data on the wire you cause a context switch because the kernel needs to handle this hardware interrupt.

So we only disagree in edge-case terminology. I think your trying to worm out of your missclassification, but no worries.

Yes, to get these numbers i have had to minimise syscalls. Thats the advantage of hellepoll. I wrote the http server just to release it, as before it was an rtmp server but it was commercial and couldn't be released. That had write buffers usr side too which helped even more.

And i understand what ab and httperf test, and yes i am counting served pages.

Finally, i spend a lot pf time staring at linux perf reports and timecharts.