docker 容器中 os.cpu_count() , multiprocessing.cpu_count() 都为物理机cpu 数
docker 容器中 os.cpu_count() , multiprocessing.cpu_count() 都为物理机cpu 数
不论起容器的时候 是否加 --cpus 1 --cpuset-cpus 0
docker 容器中 os.cpu_count() , multiprocessing.cpu_count() 都为物理机cpu 数
# native $ python -c 'import multiprocessing as mp; print(mp.cpu_count())' 12 # docker $ docker run -it --rm --cpus 1 --cpuset-cpus 0 python python -c 'import multiprocessing as mp; print(mp.cpu_count())' 12
From https://docs.docker.com/config/containers/resource_constraints/#cpu - "By default, each container’s access to the host machine’s CPU cycles is unlimited." But you can limit containers with options like --cpus or --cpuset-cpus.
--cpus can be a floating point number up to the number of physical CPU's available. You can think of this number as a numerator in the fraction <--cpus arg>/<physical CPU's>. If you have 8 physical CPU's and you specify --cpus 4, what you're telling docker is to use no more than 50% (4/8) of your total CPU's. --cpus 1.5 would use 18.75% (1.5/8).
--cpuset-cpus actually does limit specifically which physical/virtual CPU's to use.
(And there are many other CPU-related options that are covered in docker's documentation.)
https://stackoverflow.com/questions/47989418/multiprocessing-python-program-inside-docker
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
2022-06-01 模型量化