从 TCP 发送慢学习 DPDK

TCP 发送很慢 问题来自于实际生产环境下遇到的一个问题,某一个集群监控延迟 30min+,伴随丢点,包括打点 agent 本身的自监控,延迟节点上的指标 QPS 不高。

simd

概念 现代处理器利用了指令级并行技术,同一时刻存在着多条指令同时执行,如指令流水线、乱序执行等。SSE/AVX指令支持向量化数据并行,一个指令

原子操作可见性

问题 当 thread1 执行完毕后,thread2 能立马读到 7 吗? 1 2 3 4 5 std::atomic<int> x{0}; // Thread 1 x.store(7, std::memory_order_relaxed); // Thread 2 x.load(std::memory_order_relaxed); 当 thread1 和 thread2 都执行 f 后,x 的值一定是 200 吗? 1 2 3 4 5 6 7 8 9 10

mimalloc 实现分析

内存管理 Allocator 主要解决的问题包括: 高性能的内存分配 避免内存碎片化,包括内部碎片和外部碎片 Slab 系统用来实现对象缓存池 安全性保障 统计分析能力 高性能的内

rust Pin Project

再谈 pin 语义 在之前,我一直以为 pin 的作用仅仅是通过无法从 Pin<P> 获得类似 &mut T的指针,从而能确保 T 不会 move。 一旦 Pin<P> 离开作用域被 drop 时,T 就不在受 Pin 的约

c++20 coroutine

协程 什么是协程 可以在指定位置暂停,并从暂停点恢复执行 可以有多个暂停点,可以多 次返回(generator) 协程的本地数据需要持久化 协程分类 控制

协变&逆变

&mutT invariance 1 2 3 4 5 6 7 8 9 10 11 12 13 fn evil_feeder<T>(input: &mut T, val: T) { *input = val; } fn main() { let mut mr_snuggles: &'static str = "meow! :3"; // mr. snuggles forever!! { let spike = String::from("bark! >:V"); let spike_str: &str = &spike; // Only lives for the block evil_feeder(&mut mr_snuggles, spike_str); // EVIL! } println!("{}", mr_snuggles); // Use after free?

tokio-异步基础类型

为了适配 async 模型,tokio 重新实现了标准库中的 fs,net,channel 等模块,提供想对应的 async 方法。 本文以 TcpListener 为例,剖析 tokio 如何实现异步版本的

tokio-概览篇

runtime 构成 Task: runtime 每 spawn 一个异步函数就会产生一个 Task。Task 是 runtime 的调度单元,每个 Task 包含需要执行的 Future 和状态信息。 Excutor: 用来执行,管理,调

async fn memory layout

这个问题源于 rust 的一个 issue: Async fn doubles argument size 考虑下面的代码,可能会产生一下几个问题: async fn 生成的对象内存如何布局? 为什么 fut1 和 fut2 的大小不一样? 1 2 3 4 5 6 7

lifetime 小问

非词法作用域 Rust 的生命周期检查为静态检查, 并且为非词法作用域。 Rust把生命周期检查的步骤由HIR改为了MIR,以便可以降低生命周期检查的粒度

算法 滑动窗口

时间复杂度 O(n): 左右标记都最多移动 n 次 连续子区间和 窗口内的元素之和,大于给定值时,则窗口右标及之后的子数组都应该算在结果中 不能统计左下标及之前的

keep-alive

keep-alive 作用: 避免无效的资源占用。如对方挂掉,NAT 等踢掉了连接等 原理: 发送探测包,SEG.SEQ = SND.NXT-1,而 SND.NXT = RCV.NXT,即发

knowledge index

Linux 再谈 slab 伙伴算法 Socket write & read seq锁 惊群效应 BBR cache c++ 取二进制最右非 0 位:n & (~(n - 1)), 但是有溢出的风险 n & -n returns the rightmost 1 bit in n. n & (n - 1) 消除最右 1 X % 2^n =

rust Pin & Unpin

如何在 Rust 中实现一个自引用的数据结构 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 struct SelfRef<'a> { s: String, s_ref: Option<&'a mut str> } fn main() { let mut a = SelfRef { s: "hello".to_owned(), s_ref: None }; a.s_ref = Some(a.s.as_mut()); println!("{:?}", a.s_ref); // 下面代码

InnoDB 锁

事务隔离级别 READ UNCOMMITTED 脏读。 READ COMMITTED Phantom Problem。在同一事务下,连续执行两次同样的SqL语句可能有不同的结果。 REPEATABLE READ (默认) 逻辑意义上的更新丢失问题

Lock-Free简介

基本概念 Wait-freedom: Wait-freedom means that each thread moves forward regardless of external factors like contention from other threads, other thread blocking. Each operations is executed in a bounded number of steps. It’s the strongest guarantee for synchronization algorithms. Lock-freedom: Lock-freedom means that a system as a whole moves forward regardless of anything. Forward progress for each individual thread is not guaranteed (that is, individual threads can starve).