问题由来
DPDK 单worker线程使用定时器处理会话超时,会有多影响性能 ?
那么今天就来研究一下 rte_timer的性能到底如何。
测试方法
普通会话超时处理逻辑:
普通会话一直在活跃,那么需要每1分钟去check以下是否活跃,如果活跃,那么就再次设定1分钟超时;如果检查到不活跃时间不足1分钟,那么再次设定剩余时间来超时;如果不活跃时间超过1分钟(idle timeout),则删除会话。在大量用户一直活跃的时候,定时器压力最大。
我们模拟100万会话,一直循环超时回调。
set 100万个定时器,大约62s内均匀插入。
超时时间以后,触发callback, reset这个定时器, 所有定时器处在不断回调不断reset的循环之中。
每隔 1ms/ 10ms 轮询一次定时器
初始化set 100万个定时器以后,再用perf record进行记录。
测试代码
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
#include <rte_mempool.h>
#include <rte_timer.h>
#include <rte_eal.h>
#include <rte_launch.h>
#include <rte_cycles.h>
#include <rte_malloc.h>
#include <rte_lcore.h>
#define NUM_WORKERS 5
#define NUM_TIMERS_PER_WORKER 1000000
#define TIMER_RATE_PER_SECOND 25000
#define TIMEOUT_SEC 60 // 超时秒
typedef struct {
struct rte_timer timer; // DPDK 定时器
uint64_t id;
} timer_data;
int quit = 0;
#define TIMER_NUM (NUM_WORKERS * NUM_TIMERS_PER_WORKER)
struct rte_mempool *timer_mempool;
static void signal_handler(int signal) {
switch (signal) {
case SIGINT:
case SIGTERM:
printf("\n\nSignal %d