当前位置:首页>Linux>Linux 文件监控实战:inotify + epoll 从原理到 Rust 实现

Linux 文件监控实战:inotify + epoll 从原理到 Rust 实现

  • 2026-07-02 16:39:34
Linux 文件监控实战:inotify + epoll 从原理到 Rust 实现

字数 4556,阅读大约需 23 分钟

inotify 机制详解

什么是 inotify?

inotify(inode notify)是 Linux 内核 2.6.13 版本引入的文件系统事件监控机制。它允许用户空间程序监控文件系统事件,如文件创建、删除、修改等。

用户空间
Linux Kernel

文件变化

生成事件

read() 系统调用

inotify_add_watch

文件系统层
inotify 子系统
事件队列
应用程序
事件缓冲区

inotify 的核心特点

特性
说明
实时性
文件变化立即触发事件,无需轮询
高效性
基于内核事件通知,资源占用低
细粒度
可监控目录或单个文件,支持多种事件类型
易用性
通过简单的文件描述符接口操作

inotify 的局限性

  1. 1. 不递归:监控目录时不会自动监控子目录,需要手动添加
  2. 2. 无历史记录:只报告变化发生后的状态,不记录变化过程
  3. 3. 可能丢失事件:如果事件产生速度超过读取速度,会丢失事件
  4. 4. 不监控符号链接:跟随符号链接指向的实际文件

inotify API 介绍

1. inotify_init - 初始化 inotify 实例

#include <sys/inotify.h>

// 创建 inotify 实例,返回文件描述符

int
 inotify_init(void);
int
 inotify_init1(int flags);  // 带标志位的版本

返回值

  • • 成功:返回新的文件描述符(非负整数)
  • • 失败:返回 -1,设置 errno

2. inotify_add_watch - 添加监控

int inotify_add_watch(int fd, const char *pathname, uint32_t mask);

参数说明

  • • fd: inotify 实例的文件描述符
  • • pathname: 要监控的文件或目录路径
  • • mask: 监控事件掩码

常用事件掩码

事件类型
说明
IN_CREATE
文件/目录被创建
IN_DELETE
文件/目录被删除
IN_MODIFY
文件内容被修改
IN_MOVED_FROM
文件/目录被移出
IN_MOVED_TO
文件/目录被移入
IN_CLOSE_WRITE
写入操作后关闭文件
IN_ATTRIB
文件元数据改变
IN_ISDIR
事件涉及的是目录

3. inotify_rm_watch - 移除监控

int inotify_rm_watch(int fd, int wd);

4. 读取事件

#include <unistd.h>

// 使用标准的 read 系统调用读取事件

ssize_t
 read(int fd, void *buf, size_t count);

inotify_event 结构体

struct inotify_event {
    int
      wd;       /* 监控描述符 */
    uint32_t
 mask;     /* 事件掩码 */
    uint32_t
 cookie;   /* 关联相关事件(如 rename) */
    uint32_t
 len;      /* name 字段长度 */
    char
     name[];   /* 文件名(可选) */
};

inotify 工作流程

文件系统Linux Kernel应用程序文件系统Linux Kernel应用程序loop[文件系统活动-]inotify_init()返回 fdinotify_add_watch(fd, "/path", IN_CREATE|IN_DELETE)返回 watch descriptor文件创建/删除生成 inotify_event加入事件队列read(fd, buffer, size)返回 inotify_event 数据inotify_rm_watch(fd, wd)close(fd)


epoll 机制详解

什么是 epoll?

epoll 是 Linux 内核提供的一种I/O 多路复用机制,用于高效监控多个文件描述符上的事件。相比传统的 select 和 poll,epoll 在处理大量文件描述符时性能更好。

epoll 方式

epoll_ctl 增删改

回调机制

epoll_wait

应用程序
红黑树 - 存储所有 FD
内核
就绪链表
epoll 实例
select/poll 方式

每次传递全部 FD

遍历检查所有 FD

返回就绪列表

应用程序
内核
文件描述符集合

epoll 的核心优势

特性
select/poll
epoll
时间复杂度
O(n) - 需要遍历所有 FD
O(1) - 直接获取就绪事件
FD 数量限制
select 最多 1024,poll 无限制
无限制(受系统内存限制)
数据拷贝
每次调用都需拷贝整个 FD 集合
FD 一次性加入 epoll 实例,无需重复拷贝
触发模式
水平触发(LT)
支持 LT 和 ET(边缘触发)

epoll 的核心数据结构

// epoll 事件结构
struct epoll_event {

    uint32_t
     events;      /* 监控的事件类型 */
    epoll_data_t
 data;        /* 用户数据 */
};

// 用户数据联合体

typedef
union epoll_data {
    void
        *ptr;         /* 指针 */
    int
          fd;          /* 文件描述符 */
    uint32_t
     u32;
    uint64_t
     u64;
} epoll_data_t;

// 常用事件类型

#define EPOLLIN      0x001   /* 可读 */

#define EPOLLOUT     0x004   /* 可写 */

#define EPOLLERR     0x008   /* 错误 */

#define EPOLLHUP     0x010   /* 挂起 */

#define EPOLLET      0x80000000  /* 边缘触发模式 */

epoll API 介绍

1. epoll_create - 创建 epoll 实例

#include <sys/epoll.h>

// 创建 epoll 实例

int
 epoll_create(int size);        // 旧版本,size 被忽略
int
 epoll_create1(int flags);      // 新版本,推荐

返回值

  • • 成功:返回 epoll 文件描述符
  • • 失败:返回 -1,设置 errno

2. epoll_ctl - 控制 epoll 实例

int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);

参数说明

  • • epfd: epoll 实例的文件描述符
  • • op: 操作类型
    • • EPOLL_CTL_ADD: 添加 FD 到 epoll
    • • EPOLL_CTL_MOD: 修改已存在的 FD
    • • EPOLL_CTL_DEL: 从 epoll 删除 FD
  • • fd: 要操作的文件描述符
  • • event: 事件配置

3. epoll_wait - 等待事件

int epoll_wait(int epfd, struct epoll_event *events,
               int
 maxevents, int timeout)
;

参数说明

  • • epfd: epoll 实例
  • • events: 事件数组(输出参数)
  • • maxevents: 最大返回事件数
  • • timeout: 超时时间(毫秒),-1 表示无限等待

返回值

  • • 成功:返回就绪事件数量
  • • 超时:返回 0
  • • 失败:返回 -1

epoll 的触发模式

边缘触发 (ET)
事件发生
epoll_wait 返回
应用程序必须处理完所有数据
等待下次事件
水平触发 (LT)

事件发生
epoll_wait 返回
应用程序处理
数据是否读完?
等待下次事件

水平触发 (Level Triggered, LT)

  • • 默认模式
  • • 只要 FD 处于就绪状态,每次 epoll_wait 都会返回
  • • 不需要一次性读完数据

边缘触发 (Edge Triggered, ET)

  • • 通过设置 EPOLLET 标志启用
  • • 仅在状态变化时触发一次
  • • 必须一次性读完所有数据(通常配合非阻塞 I/O)

epoll 工作流程

文件描述符2文件描述符1内核epoll 实例应用程序文件描述符2文件描述符1内核epoll 实例应用程序epoll_create1(0)返回 epfdepoll_ctl(epfd, ADD, fd1, {...})将 fd1 加入监控集合epoll_ctl(epfd, ADD, fd2, {...})将 fd2 加入监控集合数据到达回调:fd1 就绪将 fd1 加入就绪链表epoll_wait(epfd, events, ...)返回就绪的 fd1read(fd1, ...)


inotify + epoll 组合架构

为什么需要组合使用?

inotify 本身是阻塞式的:read(inotify_fd) 会阻塞直到有事件发生。如果需要监控多个目录,传统的做法是为每个 inotify 实例创建单独线程,这会造成资源浪费。

epoll 提供了一种优雅的解决方案:

组合方案架构
事件处理
inotify 监控实例

监控

监控

监控

文件创建

epoll 实例

inotify fd - 监控目录 A
inotify fd - 监控目录 B
inotify fd - 监控目录 C
文件修改
文件删除

组合架构的优势

  1. 1. 单线程多路复用:一个线程监控多个目录
  2. 2. 统一事件处理:所有文件变化通过 epoll 统一分发
  3. 3. 可扩展性强:动态添加/移除监控目录
  4. 4. 资源高效:避免创建大量线程

组合工作流程

文件系统inotify 实例 Binotify 实例 Aepoll 实例主线程文件系统inotify 实例 Binotify 实例 Aepoll 实例主线程loop[事件循环]inotify_init()inotify_add_watch("/dir/A")inotify_add_watch("/dir/B")epoll_create()epoll_ctl(ADD, IN1.fd)epoll_ctl(ADD, IN2.fd)目录 A 发生文件变化触发可读事件epoll_wait()返回 IN1.fdread(IN1.fd)返回 inotify_event处理文件变化事件


Rust 实战:构建文件同步监控器

项目架构

我们将构建一个基于 inotify + epoll 的文件同步监控器,当监控目录中的文件发生变化时,自动同步到远程服务器。

系统组件
执行动作
处理模块
监控模块

事件

变化文件

rsync 同步
主线程

FileMonitor

Epoll 轮询器

inotify 实例集合
消息队列

SyncProcessor 线程

文件改名

核心代码实现

这里举了一个简陋的例子,旨在说清楚原理,并没有考虑错误处理、线程同步这些内容,大家看看,了解原理即可。

1. 文件监控模块

// monitor.rs - 文件监控模块

use
 std::cell::RefCell;
use
 std::collections::HashMap;
use
 std::io;
use
 std::os::fd::{AsRawFd, RawFd};
use
 std::path::Path;
use
 std::rc::Rc;

use
 epoll_rs::{Epoll, EpollEvent, Opts, Token};
use
 inotify::{Inotify, WatchMask};

/// 文件监控器结构

/// 封装 epoll + inotify 的组合监控逻辑

pub
 struct FileMonitor<'a> {
    /// 存储文件描述符到监控信息的映射

    monitor_dict: RefCell<HashMap<RawFd, (Token<'a, RawFd>, &'a String, Rc<Inotify>)>>,
    /// epoll 轮询器实例

    poller: Epoll,
}

impl
<'a> FileMonitor<'a> {
    /// 创建新的文件监控器

    pub
 fn new() -> Self {
        FileMonitor {
            monitor_dict: RefCell::new(HashMap::new()),
            poller: Epoll::new().expect("Failed to initialize epoll"),
        }
    }

    /// 添加监控目录

    ///

    /// # 参数

    /// * `dir` - 要监控的目录路径

    ///

    /// # 流程

    /// 1. 创建 inotify 实例

    /// 2. 使用 inotify_add_watch 添加监控

    /// 3. 将 inotify fd 添加到 epoll 轮询

    /// 4. 保存监控信息到字典

    pub
 fn add_watch(&'a self, dir: &'a String) {
        // 初始化 inotify 实例

        let
 inotify = Rc::new(
            Inotify::init().expect("Failed to initialize inotify")
        );

        // 添加监控,订阅多种事件类型

        inotify
            .watches()
            .add(
                Path::new(&(*dir)),
                WatchMask::CREATE           // 文件创建
                    | WatchMask::CLOSE_WRITE    // 写入关闭
                    | WatchMask::MOVED_FROM     // 移出
                    | WatchMask::MOVED_TO       // 移入
                    | WatchMask::MOVE_SELF,     // 自身移动
            )
            .expect("Failed to add inotify watch");

        // 获取 inotify 的文件描述符

        let
 fd = inotify.as_raw_fd();

        // 将 fd 添加到 epoll,使用边缘触发模式

        let
 token = self
            .poller
            .add(fd, Opts::IN | Opts::ET)
            .expect("Failed to add fd to epoll");

        // 保存监控信息:fd -> (token, 目录路径, inotify实例)

        self
.monitor_dict
            .borrow_mut()
            .insert(token.fd(), (token, dir, inotify));

        println!
("Watching directory {} for activity...", dir);
    }

    /// 检查指定的文件描述符是否在监控列表中

    pub
 fn contains_key(&self, key: &RawFd) -> bool {
        self
.monitor_dict.borrow().contains_key(key)
    }

    /// 获取指定 fd 对应的监控信息

    pub
 fn get(&self, key: &RawFd) -> Option<(&'a String, Rc<Inotify>)> {
        let
 map = self.monitor_dict.borrow();
        map.get(key).map(|t| (t.1, t.2.clone()))
    }

    /// epoll wait 包装函数

    /// 阻塞等待文件系统事件

    pub
 fn wait<'b>(
        &'a self,
        buf: &'b mut [EpollEvent],
    ) -> io::Result<&'b mut [EpollEvent]> {
        self
.poller.wait(buf)
    }
}

2. 同步处理模块

// sync_processor.rs - 同步处理模块

use
 std::ffi::OsStr;
use
 std::path::Path;
use
 std::process::{Command, Output};

/// 同步消息结构

/// 封装文件变化事件的相关信息

#[derive(Debug)]

pub
 struct SyncMessage {
    /// 命令类型:"rsync" 或 "mv"

    cmd: String,
    /// 是否为目录

    is_dir: bool,
    /// 文件完整路径

    file_name: String,
}

impl
 SyncMessage {
    /// 创建新的同步消息

    ///

    /// # 防循环机制

    /// 为避免多服务器间同步形成循环,通过文件名后缀标记来源:

    /// - 以 "_sync" 结尾:从其他服务器同步过来,只需本地改名

    /// - 不含标记:本地生成的文件,需要同步到远程

    pub
 fn new(path: &String, file_name: Option<&OsStr>) -> Self {
        let
 mut file = String::new();
        let
 mut cmd = String::new();

        if
 let Some(name) = file_name {
            let
 name_str = name.to_string_lossy().to_string();
            file = format!("{}/{}", *path, name_str);

            if
 name_str.ends_with("_sync") {
                // 其他服务器同步过来的文件

                cmd = "mv".to_string();
            } else if !name_str.starts_with(".") && !name_str.contains("_sync") {
                // 本地生成的文件

                cmd = "rsync".to_string();
            }
        }

        SyncMessage {
            cmd,
            is_dir: false,
            file_name: file,
        }
    }

    /// 执行 rsync 同步

    /// 将文件同步到远程服务器

    pub
 fn run_rsync(&self, remote_host: &String) {
        println!
("[sync] Starting rsync: {:?}", self);

        let
 path = Path::new(&self.file_name);
        let
 file_name = path
            .file_name()
            .unwrap()
            .to_string_lossy()
            .to_string();

        // 远程文件名添加 _sync 后缀,触发目标服务器的 mv 操作

        let
 remote_path = format!("{}{}_sync", remote_host, file_name);
        println!
("[sync] {} -> {}", file_name, remote_path);

        // 构建 rsync 命令

        let
 mut command = Command::new("rsync");
        if
 !self.is_dir {
            command.arg("-avuzP").arg(&self.file_name).arg(&remote_path);
        } else {
            command.arg("-r").arg(&self.file_name).arg(&remote_path);
        }

        // 执行并记录结果

        match
 command.output() {
            Ok
(output) => {
                if
 output.status.success() {
                    println!
("[sync] Success: {}", file_name);
                } else {
                    eprintln!
("[sync] Failed: {}", String::from_utf8_lossy(&output.stderr));
                }
            }
            Err
(err) => {
                eprintln!
("[sync] Error: {:?}", err);
            }
        }
    }

    /// 执行 mv 操作

    /// 将 _sync 后缀的文件重命名为正常文件名

    pub
 fn run_mv(&self) {
        let
 new_name = self.file_name.replace("_sync", "");
        println!
("[mv] {} -> {}", self.file_name, new_name);

        let
 mut command = Command::new("mv");
        command.arg(&self.file_name).arg(&new_name);

        if
 let Err(err) = command.output() {
            eprintln!
("[mv] Error: {:?}", err);
        }
    }

    /// 获取命令类型

    pub
 fn get_cmd(&self) -> &String {
        &self.cmd
    }
}

3. 主程序

// main.rs - 主程序

use
 std::path::{Path, PathBuf};
use
 std::sync::mpsc::{channel, Receiver, Sender};
use
 std::thread::{self, JoinHandle};
use
 std::time::Duration;

use
 inotify::EventMask;
use
 epoll_rs::EpollEvent;

mod
 monitor;
mod
 sync_processor;

use
 monitor::FileMonitor;
use
 sync_processor::SyncMessage;

/// 信号标志,用于优雅退出

static
 mut SHUTDOWN: bool = false;

/// 监控工作线程

/// 使用 epoll + inotify 监控目录变化

fn
 monitor_worker(dirs: &[String], sender: Sender<SyncMessage>) {
    // 创建文件监控器

    let
 file_monitor = FileMonitor::new();

    // 添加所有需要监控的目录

    for
 dir in dirs {
        file_monitor.add_watch(dir);
    }

    // 事件缓冲区(用于读取 inotify 事件)

    let
 mut event_buffer = [0u8; 4096];

    // epoll 事件缓冲区

    let
 mut epoll_buffer = [EpollEvent::zeroed(); 20];

    loop
 {
        // 等待事件(阻塞)

        match
 file_monitor.wait(&mut epoll_buffer) {
            Ok
(events) => {
                for
 event in events {
                    let
 fd = event.fd();

                    // 检查是否是已注册的 inotify 实例

                    if
 let Some((dir_path, inotify)) = file_monitor.get(&fd) {
                        // 读取 inotify 事件

                        match
 inotify.read_events(&mut event_buffer) {
                            Ok
(inotify_events) => {
                                for
 in_ev in inotify_events {
                                    handle_inotify_event
(in_ev, dir_path, &sender);
                                }
                            }
                            Err
(err) => {
                                eprintln!
("Failed to read inotify events: {:?}", err);
                            }
                        }
                    }
                }
            }
            Err
(err) => {
                eprintln!
("epoll wait error: {:?}", err);
                break
;
            }
        }
    }
}

/// 处理单个 inotify 事件

fn
 handle_inotify_event(
    event: inotify::Event<&OsStr>,
    dir_path: &String,
    sender: &Sender<SyncMessage>,
) {
    let
 mask = event.mask;

    // 根据事件类型处理

    if
 mask.contains(EventMask::CREATE) {
        if
 mask.contains(EventMask::ISDIR) {
            println!
("[event] Directory created: {:?}", event.name);
            // TODO: 可选 - 自动添加新目录到监控列表

        } else {
            println!
("[event] File created: {:?}", event.name);
        }
    } else if mask.contains(EventMask::DELETE) {
        println!
("[event] Deleted: {:?}", event.name);
    } else if mask.contains(EventMask::MODIFY) {
        println!
("[event] Modified: {:?}", event.name);
    } else if mask.contains(EventMask::CLOSE_WRITE) {
        if
 !mask.contains(EventMask::ISDIR) {
            // 文件写入完成,触发同步

            println!
("[event] File closed after write: {:?}", event.name);
            let
 msg = SyncMessage::new(dir_path, event.name);
            if
 !msg.get_cmd().is_empty() {
                sender.send(msg).expect("Failed to send sync message");
            }
        }
    } else if mask.contains(EventMask::MOVED_TO) {
        println!
("[event] Moved to: {:?}", event.name);
        // 处理重命名/移动的文件

        if
 let Some(name) = event.name {
            let
 name_str = name.to_string_lossy();
            if
 name_str.ends_with("_sync") {
                let
 msg = SyncMessage::new(dir_path, event.name);
                msg.run_mv();
            }
        }
    }
}

/// 同步工作线程

/// 接收消息队列中的文件变化事件并执行同步

fn
 sync_worker(receiver: Receiver<SyncMessage>, remote_servers: Vec<String>) {
    while
 let Ok(msg) = receiver.recv() {
        match
 msg.get_cmd().as_str() {
            "rsync"
 => {
                // 同步到所有远程服务器

                for
 host in &remote_servers {
                    msg.run_rsync(host);
                }
            }
            "mv"
 => {
                msg.run_mv();
            }
            _ => {}
        }
    }
}

/// 递归收集目录下的所有子目录

fn
 collect_directories(root: &str, dirs: &mut Vec<String>) {
    let
 path = Path::new(root);

    if
 let Ok(entries) = path.read_dir() {
        for
 entry in entries {
            if
 let Ok(entry) = entry {
                if
 let Ok(file_type) = entry.file_type() {
                    if
 file_type.is_dir() {
                        let
 subdir = entry.path().to_string_lossy().to_string();
                        collect_directories
(&subdir, dirs);
                        dirs.push(subdir);
                    }
                }
            }
        }
    }
}

fn
 main() {
    // 配置:监控目录列表

    let
 watch_dirs = vec![
        "/data/sync"
.to_string(),
    ];

    // 配置:远程服务器列表

    let
 remote_servers = vec![
        "server1:/data/sync/"
.to_string(),
        "server2:/data/sync/"
.to_string(),
    ];

    // 收集所有子目录

    let
 mut all_dirs: Vec<String> = Vec::new();
    for
 dir in &watch_dirs {
        all_dirs.push(dir.clone());
        collect_directories
(dir, &mut all_dirs);
    }

    println!
("Monitoring {} directories", all_dirs.len());
    for
 dir in &all_dirs {
        println!
("  - {}", dir);
    }

    // 创建消息通道

    let
 (sender, receiver) = channel();

    // 启动监控线程

    let
 monitor_handle: JoinHandle<()> = thread::spawn(move || {
        monitor_worker
(&all_dirs, sender);
    });

    // 启动同步线程

    let
 sync_handle: JoinHandle<()> = thread::spawn(move || {
        sync_worker
(receiver, remote_servers);
    });

    // 注册信号处理(优雅退出)

    setup_signal_handlers
();

    // 主循环

    loop
 {
        unsafe
 {
            if
 SHUTDOWN {
                println!
("Shutting down...");
                break
;
            }
        }
        thread::sleep(Duration::from_secs(1));
    }

    // 等待线程结束

    monitor_handle.join().unwrap();
    sync_handle.join().unwrap();
}

/// 设置信号处理

fn
 setup_signal_handlers() {
    unsafe
 {
        libc::signal(libc::SIGTERM, handle_sigterm as usize);
        libc::signal(libc::SIGINT, handle_sigint as usize);
    }
}

extern
 "C" fn handle_sigterm(_: i32) {
    unsafe
 {
        SHUTDOWN = true;
    }
}

extern
 "C" fn handle_sigint(_: i32) {
    unsafe
 {
        SHUTDOWN = true;
    }
}

工作流程图解

远程服务器同步线程inotifyepollFileMonitor监控线程主线程远程服务器同步线程inotifyepollFileMonitor监控线程主线程loop[初始化监控目录]事件循环文件名添加 _sync 后缀alt[CLOSE_WRITE 事件][MOVED_TO 事件(带 _sync 后缀)]启动监控线程FileMonitor::new()epoll_create()inotify_init()返回 inotify_fdinotify_add_watch("/dir")add_watch(dir)epoll_ctl(ADD, inotify_fd)启动同步线程sleep 等待事件目录发生文件变化epoll_wait 返回就绪事件read(inotify_fd)返回事件详情解析事件sender.send(msg)rsync 同步文件同步完成mv 去掉 _sync 后缀


常见问题与优化建议

Q1: inotify 事件丢失怎么办?

原因:当事件产生速度超过处理速度时,inotify 事件队列会溢出。

解决方案

  1. 1. 增大缓冲区
// 使用更大的事件缓冲区
let
 mut event_buffer = [0u8; 8192];  // 原来是 4096
  1. 2. 使用非阻塞 I/O + 边缘触发
// 设置非阻塞模式
fcntl
(fd, F_SETFL, O_NONBLOCK);

// epoll 使用边缘触发

epoll_ctl
(epfd, EPOLL_CTL_ADD, fd, 
    &(EpollEvent { events: EPOLLIN | EPOLLET, data: ... }));
  1. 3. 多线程处理:将事件分发到多个工作线程处理

Q2: 如何递归监控目录树?

方案:动态添加子目录监控

fn watch_recursive(monitor: &FileMonitor, root: &str) {
    // 首先监控根目录

    monitor.add_watch(root);

    // 递归遍历子目录

    for
 entry in WalkDir::new(root) {
        if
 let Ok(e) = entry {
            if
 e.file_type().is_dir() {
                monitor.add_watch(&e.path().to_string_lossy());
            }
        }
    }
}

// 处理 CREATE 事件时动态添加新目录

if
 mask.contains(EventMask::CREATE) && mask.contains(EventMask::ISDIR) {
    let
 new_dir = format!("{}/{}", base_path, name);
    file_monitor.add_watch(&new_dir);
}

Q3: epoll_wait 被信号中断怎么处理?

loop {
    match
 file_monitor.wait(&mut epoll_buffer) {
        Ok
(events) => { /* 处理事件 */ }
        Err
(ref e) if e.kind() == std::io::ErrorKind::Interrupted => {
            // 被信号中断,继续循环

            continue
;
        }
        Err
(e) => {
            eprintln!
("epoll error: {:?}", e);
            break
;
        }
    }
}

Q4: 性能优化建议

优化点
建议
缓冲区大小
使用 epoll 批量读取事件,减少系统调用次数
边缘触发
对高频率变化的文件使用 EPOLLET 模式
线程池
同步操作使用线程池,避免阻塞监控线程
批量同步
累积多个文件变化后批量执行 rsync
忽略临时文件
过滤编辑器临时文件(如 .swp~

Q5: 调试技巧

// 启用 inotify 调试日志
std::env::set_var("RUST_LOG", "debug");

// 打印所有事件

println!
("[debug] Event mask: {:?}", mask);
println!
("[debug] Event name: {:?}", event.name);
println!
("[debug] Event cookie: {:?}", event.cookie);

// 统计事件频率

use
 std::sync::atomic::{AtomicUsize, Ordering};
static
 EVENT_COUNT: AtomicUsize = AtomicUsize::new(0);

fn
 log_event() {
    let
 count = EVENT_COUNT.fetch_add(1, Ordering::SeqCst);
    println!
("Total events: {}", count);
}

总结

inotify 负责文件变化通知,epoll 负责多路复用调度,两者结合就能用单线程高效监控多个目录。这套模式常见于日志收集、文件同步、自动构建等场景。


参考资源

  • • Linux inotify man page[1]
  • • Linux epoll man page[2]
  • • inotify-rs crate[3]
  • • epoll-rs crate[4]
  • • The Linux Programming Interface[5]

引用链接

[1] Linux inotify man page: https://man7.org/linux/man-pages/man7/inotify.7.html
[2] Linux epoll man page: https://man7.org/linux/man-pages/man7/epoll.7.html
[3] inotify-rs crate: https://docs.rs/inotify/latest/inotify/
[4] epoll-rs crate: https://docs.rs/epoll-rs/latest/epoll_rs/
[5] The Linux Programming Interface: https://man7.org/tlpi/

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 04:01:10 HTTP/2.0 GET : https://f.mffb.com.cn/a/495815.html
  2. 运行时间 : 0.184357s [ 吞吐率:5.42req/s ] 内存消耗:5,013.77kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=b7ecf77c2c718480b692ff5d61fb7f38
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000435s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000848s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000762s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.002996s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000515s ]
  6. SELECT * FROM `set` [ RunTime:0.003320s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000574s ]
  8. SELECT * FROM `article` WHERE `id` = 495815 LIMIT 1 [ RunTime:0.013983s ]
  9. UPDATE `article` SET `lasttime` = 1783022470 WHERE `id` = 495815 [ RunTime:0.024787s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 67 LIMIT 1 [ RunTime:0.004638s ]
  11. SELECT * FROM `article` WHERE `id` < 495815 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.002358s ]
  12. SELECT * FROM `article` WHERE `id` > 495815 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000766s ]
  13. SELECT * FROM `article` WHERE `id` < 495815 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.039244s ]
  14. SELECT * FROM `article` WHERE `id` < 495815 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.018847s ]
  15. SELECT * FROM `article` WHERE `id` < 495815 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.001912s ]
0.185943s