当nova控制节点、计算节点上的服务启动后,可以看到,nova-api/nova-scheduler/nova-conductor这些进程里面都只有一个线程:
[root@controller ~]# ps -elf | grep
nova-api
4 S nova 30432 1 0 80 0 - 86154 poll_s Jan09 ? 03:22:30 /usr/bin/python /usr/bin/nova-api
1 S nova 30555 30432 0 80 0 - 82085 ep_pol Jan09 ? 00:00:01 /usr/bin/python /usr/bin/nova-api
1 S nova 30556 30432 0 80 0 - 82085 ep_pol Jan09 ? 00:00:01 /usr/bin/python /usr/bin/nova-api
1 S nova 30667 30432 0 80 0 - 122854 ep_pol Jan09 ? 00:03:48 /usr/bin/python /usr/bin/nova-api
1 S nova 30668 30432 0 80 0 - 122710 ep_pol Jan09 ? 00:03:50 /usr/bin/python /usr/bin/nova-api
1 S nova 30708 30432 0 80 0 - 86612 ep_pol Jan09 ? 00:00:01 /usr/bin/python /usr/bin/nova-api
1 S nova 30709 30432 0 80 0 - 86613 ep_pol Jan09 ? 00:00:01 /usr/bin/python /usr/bin/nova-api
[root@controller ~]# ll /proc/ 30432 /task/
total 0
dr-xr-xr-x 6 nova nova 0 Jan 28 08:51 30432
4 S nova 30432 1 0 80 0 - 86154 poll_s Jan09 ? 03:22:30 /usr/bin/python /usr/bin/nova-api
1 S nova 30555 30432 0 80 0 - 82085 ep_pol Jan09 ? 00:00:01 /usr/bin/python /usr/bin/nova-api
1 S nova 30556 30432 0 80 0 - 82085 ep_pol Jan09 ? 00:00:01 /usr/bin/python /usr/bin/nova-api
1 S nova 30667 30432 0 80 0 - 122854 ep_pol Jan09 ? 00:03:48 /usr/bin/python /usr/bin/nova-api
1 S nova 30668 30432 0 80 0 - 122710 ep_pol Jan09 ? 00:03:50 /usr/bin/python /usr/bin/nova-api
1 S nova 30708 30432 0 80 0 - 86612 ep_pol Jan09 ? 00:00:01 /usr/bin/python /usr/bin/nova-api
1 S nova 30709 30432 0 80 0 - 86613 ep_pol Jan09 ? 00:00:01 /usr/bin/python /usr/bin/nova-api
[root@controller ~]# ll /proc/ 30432 /task/
total 0
dr-xr-xr-x 6 nova nova 0 Jan 28 08:51 30432
[root@controller ~]# ll /proc/ 30555 /task/
total 0
dr-xr-xr-x 6 nova nova 0 Jan 28 08:56 30555
[root@controller ~]# ps -elf | grep nova-scheduler
4 S nova 30480 1 0 80 0 - 112849 ep_pol Jan09 ? 00:19:17 /usr/bin/python /usr/bin/nova-scheduler
[root@controller ~]# ll /proc/ 30480 /task/
total 0
dr-xr-xr-x 6 nova nova 0 Jan 28 08:51 30480
[root@controller ~]# ps -elf | grep nova-conductor
4 S nova 30590 1 0 80 0 - 80706 poll_s Jan09 ? 03:18:40 /usr/bin/python /usr/bin/nova-conductor
1 S nova 30703 30590 1 80 0 - 124545 ep_pol Jan09 ? 05:01:42 /usr/bin/python /usr/bin/nova-conductor
1 S nova 30705 30590 1 80 0 - 126273 ep_pol Jan09 ? 04:59:16 /usr/bin/python /usr/bin/nova-conductor
[root@controller ~]# ll /proc/ 30590 /task/
total 0
dr-xr-xr-x 6 nova nova 0 Jan 28 08:51 30590
[root@controller ~]# ll /proc/ 30703 /task/
total 0
dr-xr-xr-x 6 nova nova 0 Jan 28 08:59 30703
唯独nova-compute比较特殊些:
[root@controller ~]# ps -elf | grep nova-compute
4 S nova 30495 1 0 80 0 - 451771 ep_pol Jan09 ? 03:01:45 /usr/bin/python /usr/bin/nova-compute
[root@controller ~]# ll /proc/30495/task/
total 0
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30495
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30732
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30733
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30734
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30735
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30736
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30737
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30738
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30739
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30740
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30741
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30742
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30743
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30744
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30745
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30746
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30747
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30748
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30749
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30750
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30751
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30784
4 S nova 30495 1 0 80 0 - 451771 ep_pol Jan09 ? 03:01:45 /usr/bin/python /usr/bin/nova-compute
[root@controller ~]# ll /proc/30495/task/
total 0
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30495
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30732
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30733
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30734
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30735
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30736
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30737
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30738
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30739
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30740
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30741
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30742
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30743
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30744
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30745
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30746
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30747
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30748
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30749
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30750
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30751
dr-xr-xr-x 6 nova nova 0 Jan 28 08:52 30784
共计22个线程,其实有20个来自tpool,数量由
EVENTLET_THREADPOOL_SIZE决定,默认值为20。
另外还有两个,一是libvirtd线程,另一个就是同api/scheduler/conductor类似的“协程管理”线程了。
这个线程在实际运行时,负责调度执行N个协程,而协程的数量是在动态变化的,
协程管理线程按照不同的时间片,执行不同的协程,
并且可以对这些协程进行分组管理(常见的是用self.tg来表示一个组):
每个tg即是一个ThreadGroup,每个ThreadGroup里面都有一个GreenPool,例如:
GreenPool1:GreenThread1/GreenThread2
GreenPool2:GreenThread3
GreenPool3:GreenThread4/GreenThread5
nova的每个进程中用于创建、切分、管理协程的线程只有一个,这个线程中划分出来的众多协程通过GreenPool进行分组。