Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
dielianxiang
V2EX  ›  Linux

Linux 求教:多核 CPU 电脑,指定不同的进程(应用)使用不同的 CPU 运行。

  •  
  •   dielianxiang · Jul 11, 2018 · 4885 views
    This topic created in 2872 days ago, the information mentioned may be changed or developed.

    事情是这样的:

    公司有一个项目,需要实时传输视频,然后对视频的每一帧进行图像处理。而图像处理或者其他程序运行后,cpu 会突然高一阵子,这就导致视频传输的进程的时间片被抢占,导致丢包。

    故想如何避免这个问题?

    目前我的想法是视频传输进程使用单独的 CPU,其他程序使用其他的 CPU,应该就不会发生这样的问题了。那么问题来了,linux 里面如何实现呢?

    19 replies    2018-07-12 16:50:02 +08:00
    coderfox
        1
    coderfox  
       Jul 11, 2018 via Android
    限制一下视频处理的线程数更简单吧。
    dielianxiang
        2
    dielianxiang  
    OP
       Jul 11, 2018
    @coderfox 这两个程序都是必要的。改动的可能性不大。
    ryd994
        3
    ryd994  
       Jul 11, 2018   ❤️ 2
    taskset
    但是我觉得你这种情况用 nice 和或 chrt 更好,因为 taskset 只能保证这个进程不抢其他人,不代表其他人不抢它。
    虽然也可以用 isolcpu,但是你这种情况应该还用不上
    privil
        4
    privil  
       Jul 11, 2018   ❤️ 3
    cpulimit cgroups 了解一下
    danc
        5
    danc  
       Jul 11, 2018
    一定是你的机器不信,加机器配置呗
    lihongjie0209
        6
    lihongjie0209  
       Jul 11, 2018
    如果可以的话, 把图像处理和视频传输分散到两台机器上, 中间用消息队列

    关于丢包, 这个要具体分析了:
    1. 什么协议
    2. 什么情况下丢包
    lihongjie0209
        7
    lihongjie0209  
       Jul 11, 2018
    @privil #4 这个不错
    linyinma
        8
    linyinma  
       Jul 11, 2018
    CPU 亲和性设置

    /* API */
    /* Set the CPU affinity for a task */
    int sched_setaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);
    /* Get the CPU affinity for a task */
    int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);

    /* set CPU affinity attribute in thread attributes object */
    int pthread_attr_setaffinity_np(pthread_attr_t *attr, size_t cpusetsize, const cpu_set_t *cpuset);
    /* get CPU affinity attribute in thread attributes object */
    int pthread_attr_getaffinity_np(const pthread_attr_t *attr, size_t cpusetsize, cpu_set_t *cpuset);

    /* set CPU affinity of a thread */
    int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset);
    /* get CPU affinity of a thread */
    int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset);
    a7a2
        9
    a7a2  
       Jul 11, 2018
    直接 使用命令 nice 修改改变进程优先级 即可
    sleeperqp
        10
    sleeperqp  
       Jul 11, 2018 via iPhone
    cpu 亲和性+1
    henglinli
        11
    henglinli  
       Jul 11, 2018 via iPhone
    估计是监控视频的人脸识别
    tempdban
        12
    tempdban  
       Jul 12, 2018 via Android
    补充一点 内核 boot 参数要设好核隔离。
    你这个稍微有点性能优化的意思,提醒一句 SIMD 用了没?
    msg7086
        13
    msg7086  
       Jul 12, 2018
    X 问题:如何防止重要进程的 CPU 被抢占。
    Y 问题:如何指定进程使用不同的 CPU 运行。

    XY 问题了解一下。
    guanhui07
        14
    guanhui07  
       Jul 12, 2018
    cpulimit
    defel
        15
    defel  
       Jul 12, 2018 via iPhone
    slurm 可以解决,直接指定计算节点。
    dielianxiang
        16
    dielianxiang  
    OP
       Jul 12, 2018
    我都试试 谢谢各位,结果我后面根据测试结论告知大家
    dielianxiang
        17
    dielianxiang  
    OP
       Jul 12, 2018
    @henglinli 比这个高级多了
    checgg
        18
    checgg  
       Jul 12, 2018
    docker 直接跑 docker 里面满足你的要求吗
    freemon
        19
    freemon  
       Jul 12, 2018
    cpu 亲和性,可以先做 cpu isolate,然后设置 affinity 指定进程绑定一个或者一组 cpu
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1074 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 100ms · UTC 23:20 · PVG 07:20 · LAX 16:20 · JFK 19:20
    ♥ Do have faith in what you're doing.