4 ms·
Well, one advantage the Go runtime has is the green threads are cooperatively scheduled, so switches are a lot more lightweight.
by openasocket 10y ago
Well, one advantage the Go runtime has is the green threads are cooperatively scheduled, so switches are a lot more lightweight.
- pcwalton 10y ago> Well, one advantage the Go runtime has is the green threads are cooperatively scheduled, so switches are a lot more lightweight. Switches occur on timeouts (which involve a round trip through the kernel), on I/O events (which also involve a round trip through the kernel), or on goroutine message passing. So in every case except goroutine message sends, the switches don't actually save you a trip through the kernel.
- gpderetta 10y agoExcept when the IO doesn't go though the kernel in the first place of course.
- pcwalton 10y agoWhat I/O doesn't go through the kernel?
- gpderetta 10y agoFor the example if you are using kernel bypass of the network stack, which is increasingly common in high throughput/low latency applications.
- saosebastiao 10y agoIs anybody doing kernel bypass networking in go?
- haimez 10y agoIf you're going to bypass the kernel network stack for performance, you're definitely not going to write the rest of your code in go. The garbage collector, goroutine scheduler, and conservative compile time optimizations will totally undermine the end goal. If you're in that world, you're using C, C++, or That if you're feeling dangerous.
- kasey_junk 10y agoI've done kernel bypass work on the JVM.
- pjmlp 10y agoThe JVM is used a lot in Fintech. Of course it isn't the OpenJDK, rather specialized JVMs like Azul or they code using C style coding with the GC out of the out paths, having profiled the applications with tools like Java Mission Control. These are the customers driving Oracles effort for value types, AOT compilation and JNI replacement. Why not just use C and C++, one might ask? In spite of all these tricks and required knowledge, salaries are lower than for C and C++ developers and overall project costs are anyway lower due to shorter development times for the other tools not available in C and C++. Hence why Fintech nowadays is looking into languages like Pony, because they don't want to wait for Java 10, if possible. So an area where Rust might eventually earn some friends.
- gpderetta 10y agoFWIW, I wasn't thinking bout go.
- Matthias247 10y agoFor I/O you can buffer inside the application whether the respective file is readable/writeable or not. If it's not readable you can directly switch to another goroutine without invoking a syscall. The scheduler will later get notified by select/epoll that the file is readable/writeable, adjust the buffered status and reschedule the goroutine. But ok, for reading you might often have a buffered state of readable while in reality it's not and you only get this information through EAGAIN on read, so you won't avoid the syscall there. For writing you most likely always would.
- tomp 10y agoCouldn't you switch on timeout using some kind of CPU counter, e.g. RDTSC?
- saynsedit 10y agoSystem call context switching is cheaper than and different from thread/scheduler context switching.