Skip to content

Instantly share code, notes, and snippets.

View pavel-odintsov's full-sized avatar
🛡️
On mission to deliver affordable DDoS protection

Pavel Odintsov pavel-odintsov

🛡️
On mission to deliver affordable DDoS protection
View GitHub Profile
/*
* Test functionality of BPF filters for SO_REUSEPORT. The tests below will use
* a BPF program (both classic and extended) to read the first word from an
* incoming packet (expected to be in network byte-order), calculate a modulus
* of that number, and then dispatch the packet to the Nth socket using the
* result. These tests are run for each supported address family and protocol.
* Additionally, a few edge cases in the implementation are tested.
*/
#include <errno.h>
@pavel-odintsov
pavel-odintsov / reuseport_bpf.c
Created August 24, 2023 20:30
reuseport_bpf.c
/*
* Test functionality of BPF filters for SO_REUSEPORT. The tests below will use
* a BPF program (both classic and extended) to read the first word from an
* incoming packet (expected to be in network byte-order), calculate a modulus
* of that number, and then dispatch the packet to the Nth socket using the
* result. These tests are run for each supported address family and protocol.
* Additionally, a few edge cases in the implementation are tested.
*/
#include <errno.h>
@pavel-odintsov
pavel-odintsov / reuseport.cpp
Last active August 24, 2023 19:47
reuseport.cpp
#include <iostream>
#include <thread>
#include <sys/socket.h>
#include <string.h>
#include <netdb.h>
#include <linux/filter.h>
void start_netflow_collector(const std::string& netflow_host, unsigned int netflow_port, bool reuse_port, uint32_t netflow_threads_per_port) {
Mar 24 18:38:07 webui-ubuntu2204 ferretdb[49559]: 2023-03-24T18:38:07.624Z INFO listener clientconn/listener.go:305 Connection started {"conn": "127.0.0.1:51308 -> 127.0.0.1:27017"}
Mar 24 18:38:07 webui-ubuntu2204 ferretdb[49559]: 2023-03-24T18:38:07.624Z INFO listener clientconn/listener.go:305 Connection started {"conn": "127.0.0.1:51296 -> 127.0.0.1:27017"}
Mar 24 18:38:07 webui-ubuntu2204 ferretdb[49559]: 2023-03-24T18:38:07.627Z INFO listener clientconn/listener.go:305 Connection started {"conn": "127.0.0.1:51314 -> 127.0.0.1:27017"}
Mar 24 18:38:07 webui-ubuntu2204 ferretdb[49559]: 2023-03-24T18:38:07.635Z INFO pgdb v4@v4.18.1/conn.go:354 Dialing PostgreSQL server {"host": "127.0.0.1"}
Mar 24 18:38:07 webui-ubuntu2204 ferretdb[49559]: 2023-03-24T18:38:07.647Z INFO pgdb v4@v4.18.1/conn.go:354 Query {"sql": "SHOW server_version", "a
@pavel-odintsov
pavel-odintsov / gist:f21655367ce64229162347486c70ad6e
Created February 26, 2023 22:42
Boost 1.81 unordered_flat_map
./traffic_structures_tests_real_traffic
Loaded 183978 IPs into memory
std::map big endian
Total lookup time is 63 seconds
Million of lookup ops per second: 2.93322
Total scan time is 16 seconds
Million of full scan ops per second: 8.19823
std::map little endian
@pavel-odintsov
pavel-odintsov / unbound.conf
Created December 31, 2022 20:27
Unbound for IPv6 enabled home network
server:
# Set to number of big ARM cores on my board RockPro64
# TODO: adjust it for your machine but no reasons to make it more then 4-8 as it will increase lock contention
num-threads: 2
# Listen on all interfaces for IPv4
interface: 0.0.0.0
# Listen on all interfaces for IPv6
interface: ::0
@pavel-odintsov
pavel-odintsov / gist:d215348013cb087e6396d27e0199d6a8
Last active December 11, 2022 12:46
Ubuntu 22.04 in Docker on Ubuntu 22.04

Create Docker image with systemd enabled:

echo -e "FROM ubuntu:22.04\nENV DEBIAN_FRONTEND noninteractive\nRUN apt-get update; apt-get upgrade; apt-get install -y systemd systemd-sysv; \nCMD ["/lib/systemd/systemd"]" | sudo docker build --tag debian_systemd -

Try running it:

sudo docker run -d -v /home/circleci:/home/circleci -v /sys/fs/cgroup/:/sys/fs/cgroup:ro --privileged --cap-add SYS_ADMIN --name linux_systemd_container_random debian_systemd /lib/systemd/systemd

Then check status:

@pavel-odintsov
pavel-odintsov / gist:ab5a6ccaca9bf60cd21d7454c8e383aa
Created July 1, 2022 18:22
AMD Ryzen 5 3600 6-Core Processor test with Absl flat_hash_map and node_hash_map
Loaded 183978 IPs into memory
std::map big endian
Total lookup time is 59 seconds
Million of lookup ops per second: 3.11381
Total scan time is 15 seconds
Million of full scan ops per second: 8.43543
Accumulator value to guarantee no optimisation tricks from compiler: 183978000000
std::map little endian
@pavel-odintsov
pavel-odintsov / gist:d63ddddce89f5a5750076d45bd23eee0
Created July 1, 2022 18:04
Small key real traffic performance
Loaded 183978 IPs into memory
std::map big endian
Total lookup time is 28 seconds
Million of lookup ops per second: 6.46384
Total scan time is 3 seconds
Million of full scan ops per second: 49.8883
Accumulator value to guarantee no optimisation tricks from compiler: 183978000000
std::map little endian
@pavel-odintsov
pavel-odintsov / gist:31f2b393f45d10445283dfd6459a35e3
Created July 1, 2022 17:47
Absl vs Boost 1.80 vs std::unordered_map
Loaded 183978 IPs into memory
AMD Ryzen 5 3600 6-Core Processor
std::map big endian
Total lookup time is 58 seconds
Million of lookup ops per second: 3.12534
Total scan time is 16 seconds
Million of full scan ops per second: 8.33437
Accumulator value to guarantee no optimisation tricks from compiler: 183978000000