1
0
Fork 0
mirror of https://gitee.com/fantix/kloop.git synced 2024-11-21 18:01:00 +00:00
No description
Find a file
2022-06-26 11:48:34 -04:00
resolver Clean up Rust project 2022-06-26 11:48:34 -04:00
src/kloop Implement UDP recv, basic DNS working! 2022-06-26 11:48:07 -04:00
tests Almost working PoC 2022-04-19 18:32:40 -04:00
.gitignore v0.0.1: Initial project structure 2022-03-19 17:26:56 -04:00
architecture.en.png Correct links and images in README 2022-06-26 11:48:32 -04:00
architecture.zh.png Correct links and images in README 2022-06-26 11:48:32 -04:00
LICENSE v0.0.1: Initial project structure 2022-03-19 17:26:56 -04:00
Makefile Update README and add Makefile 2022-03-19 17:41:48 -04:00
MANIFEST.in Correct links and images in README 2022-06-26 11:48:32 -04:00
pyproject.toml PoC uring and ktls 2022-03-20 19:07:05 -04:00
README.md Add dev steps in README 2022-06-26 11:48:34 -04:00
README.zh.md Add dev steps in README 2022-06-26 11:48:34 -04:00
setup.cfg Add dev steps in README 2022-06-26 11:48:34 -04:00
setup.py WIP resolver 2022-06-26 11:48:06 -04:00

kLoop

中文

kLoop is an implementation of the Python asyncio event loop written in Cython, using io_uring and kTLS features of the Linux kernel, therefore called k(ernel)Loop.

kLoop is open-sourced and released under the MulanPSL - 2.0 license.

⚠️WARNING: THIS PROJECT IS IN PROOF-OF-CONCEPT STAGE!⚠️

Features

  • Minimum syscalls - all I/O calls are done in the kernel thanks to io_uring, and the only remaining syscall to io_uring_enter() is also optimized to be only called when necessary using the SQPOLL feature. That means most of the overhead of syscalls is gone;
  • No GIL in the main-loop - the hot-path is written in Cython without GIL, that means it's compiled into pure C code without Python structures, saving some memory and execution time. On the other hand, GIL is only taken before Python callbacks, so it's slightly more friendly to multithreading, which is still not recommended though.
  • TLS offloading - all symmetric-key encryption and decryption work is offloaded to the NIC if supported, or to the thread pool of io_uring otherwise. This allows us to free up CPU for more I/O, or leverage all the CPU cores even if the application is running single-threaded.
  • Asynchronous DNS resolving - we blended in the Rust trust-dns library with a custom I/O runtime bridging to io_uring in C (including reading the /etc/resolv.conf and /etc/hosts files), providing flexible APIs to manage the concurrency, cache and configuration in Python.

Requirements

  • Python >= 3.10
  • Linux >= 5.11 (enable kTLS with modprobe tls)
  • OpenSSL >= 3.0 (kTLS receive offloading requires the latest development version)

Development and testing is done on Ubuntu 22.04.

Architecture Diagram

architecture.png

Looks like the Lucky Charms factory, says @aaronbrighton ...

Development

Ubuntu 22.04

sudo apt update
sudo apt install gcc libssl-dev python3-dev python3.10-venv
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
python3 -m venv path/to/env
source path/to/env/bin/activate
pip install -e path/to/kloop