https://geocar.sdf1.org/fast-servers.html #reinventingthewheel #networkserver #epoll #kqueue #softwaredevelopment #HackerNews #ngated
Событийный цикл в asyncio: как Python-код работает поверх механизмов Linux
Большая статья для тех, кто, как и я, споткнулся об asyncio и так не разгадал до конца "магию" событийного цикла. Попробовал распутать этот клубок через подробный рассказ (в как можно более доступной форме) о внутренних механизмах Линукса и самого asyncio, которые лежат в основе событийного. К концу статьи, надеюсь, магия исчезнет, а останется ясное понимание фундамента. Погружаемся
https://habr.com/ru/articles/995032/
#asyncio #python #epoll #selectors #асинхронность #event_loop #eventloop #linux #сокеты
Как я пытался внедрить IOCP в libcoro, выгорел на полгода, но вернулся с планом «Б»
Что делать, если в твоём очередном самописном движке внезапно понадобилась сеть, да ещё и на корутинах из C++ 20, а подходящая библиотека не поддерживает Windows? Правильно - лезть под капот, разбираться что такое epoll , почему он несовместим с IOCP, затем вкатиться в Open Source, сделав огромный PR, выгореть на полгода, чтобы потом вернуться и начать делать нормально. Небольшая история о том, почему первый PR не должен быть огромным и как (не) нужно переписывать сетевую библиотеку.
https://habr.com/ru/articles/993666/
#c++20 #корутины #асинхронный_вводвывод #epoll #iocp #кроссплатформенность
muRPC: Реализация протокола JSON-RPC на C++
Данная статья описывает библиотеку muRPC для создания сервера и клиента для протокола JSON-RPC. Режим работы предполагает, что один из клиентов JSON-RPC предоставляет какие-то методы и сообщает об этом серверу. Тогда другие клиенты JSON-RPC могут эти методы вызывать и получать ответ. Сервер предоставляет маршрутизацию и валидацию сообщений между клиентами. Область применения — это любые системы, где требуется обмен сообщениями, удобно соединяемый с вызовом программных функций.
I/O Multiplexing (select vs. poll vs. epoll/kqueue)
Please help me spread the link to #swad 😎
https://github.com/Zirias/swad
I really need some users by now, for those two reasons:
* I'm at a point where I fully covered my own needs (the reasons I started coding this), and getting some users is the only way to learn about what other people might need
* The complexity "exploded" after supporting so many OS-specific APIs (like #kqueue, #epoll, #eventfd, #signalfd, #timerfd, #eventports) and several #lockfree implementations based on #atomics while still providing fallbacks for everything that *should* work on any #POSIX systems ... I'm definitely unable at this point to think of every possible edge case and test it. If there are #bugs left (which is somewhat likely), I really need people reporting these to me
Thanks! 🙃
Today, it's exactly one month since I released #swad 0.11. And I'm slowly closing in on releasing 0.12.
The change to a "multi #reactor" design was massive. It pays off though. On the hardware that could reach a throughput of roughly 1000 requests per second, I can now support over 3000 r/s, and when disabling #TLS, 10 times as much. Most of the time, I spent with "detective work" to find the causes for a variety of crashes, and now I'm quite confident I found them all, at least on #FreeBSD with default options. As 0.11 still has a bug affecting for example the #epoll backend on #Linux, expect to see swad 0.12 released very very soon.
I'm still not perfectly happy with RAM consumption (although that could also be improved by explicitly NOT releasing some objects and reusing them instead), and there are other things that could be improved in the future, e.g. experiment with how to distribute incoming connections to the worker threads, so there's not one "loser" that always gets slowed down massively by all the others. Or design and implement alternative #JWT #signature algorithms besides #HS256 which could enable horizontal scaling via load balancing. Etc. But I think the improvements for now are enough for a release. 😉
Getting somewhat closer to releasing a new version of #swad. I now improved the functionality to execute something on a different worker thread: Use an in-memory queue, providing a #lockfree version. This gives me a consistent reliable throughput of 3000 requests/s (with outliers up to 4500 r/s) at an average response time of 350 - 400 ms (with TLS enabled). For waking up worker threads, I implemented different backends as well: kqueue, eventfd and event-ports, the fallback is still a self-pipe.
So, #portability here really means implement lots of different flavors of the same thing.
Looking at these startup logs, you can see that #kqueue (#FreeBSD and other BSDs) is really a "jack of all trades", being used for "everything" if available (and that's pretty awesome, it means one single #syscall per event loop iteration in the generic case). #illumos' (#Solaris) #eventports come somewhat close (but need a lot more syscalls as there's no "batch registering" and certain event types need to be re-registered every time they fired), they just can't do signals, but illumos offers Linux-compatible signalfd. Looking at #Linux, there's a "special case fd" for everything. 🙈 Plus #epoll also needs one syscall for each event to be registered. The "generic #POSIX" case without any of these interfaces is just added for completeness 😆