-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfe7629
commit 0235adf
Showing
32 changed files
with
619 additions
and
6 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...c/kubernetes/concepts/configuration/article-k8s-capacity-taint-tollerations.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
|
||
根据 :ref:`deploy_centos7_gluster11` 迭代改进部署方案 | ||
|
||
**待续** | ||
|
||
准备工作 | ||
=========== | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.. _process_vs_thread: | ||
|
||
====================== | ||
process vs. thread | ||
====================== | ||
|
||
进程是程序执行时的一个实例,即它是程序已经执行到何种程度的数据结构的汇集。从内核的观点看,进程的目的就是担当分配系统资源(CPU时间、内存等)的基本单位。 | ||
|
||
线程是进程的一个执行流,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位。一个进程由几个线程组成(拥有很多相对独立的执行流的用户程序共享应用程序的大部分数据结构),线程与同属一个进程的其他的线程共享进程所拥有的全部资源。 | ||
|
||
进程有独立的地址空间,一个进程崩溃后,在保护模式下不会对其它进程产生影响,而线程只是一个进程中的不同执行路径。线程有自己的堆栈和局部变量,但线程没有单独的地址空间,一个线程死掉就等于整个进程死掉,所以多进程的程序要比多线程的程序健壮,但在进程切换时,耗费资源较大,效率要差一些。但对于一些要求同时进行并且又要共享某些变量的并发操作,只能用线程,不能用进程。 | ||
|
||
进程和线程两个模型的差异在于, 进程更安全,一个进程完全不会影响另外的进程。所以这也是 unix 哲学里推荐的编程方法; 但是进程间通信比线程间通信的性能差很多,尤其是,如果这个是系统的关键部分,而又有大量数据的时候,所有的进程间通信方法都比线程间的通信慢很多。 | ||
|
||
所以通常情况下推荐多进程程序,就像 :ref:`nginx` ,一个 master 多个 worker,进程间只进行有限的通信(传递命令而非数据)。多线程的典型例子是 ``unbound`` ,一个开源的递归 dns 服务器。它使用线程的理由也很充分:程序需要不停地向后方的授权 dns 请求数据,并传回给前方的模块。这个数据通信量大,性能要求又高,所以必须用多线程,如果是多个进程,那就要慢许多了。 | ||
|
||
使用线程的理由 | ||
================ | ||
|
||
使用多线程的理由之一是和进程相比,它是一种非常 "节俭" 的多任务操作方式。我们知道,在Linux系统下,启动一个新的进程必须分配给它独立的地址空间,建立众多的数据表来维护它的代码段、堆栈段和数据段,这是一种"昂贵"的多任务工作方式。 | ||
|
||
而运行于一个进程中的多个线程,它们彼此之间使用相同的地址空间,共享大部分数据,启动一个线程所花费的空间远远小于启动一个进程所花费的空间,而且,线程间彼此切换所需的时间也远远小于进程间切换所需要的时间。据统计,总的说来,一个进程的开销大约是一个线程开销的30倍左右,当然,在具体的系统上,这个数据可能会有较大的区别。 | ||
|
||
使用多线程的理由之二是线程间方便的通信机制。对不同进程来说,它们具有独立的数据空间,要进行数据的传递只能通过通信的方式进行,这种方式不仅费时,而且很不方便。线程则不然,由于同一进程下的线程之间共享数据空间,所以一个线程的数据可以直接为其它线程所用,这不仅快捷,而且方便。当然,数据的共享也带来其他一些问题,有的变量不能同时被两个线程所修改,有的子程序中声明为static的数据更有可能给多线程程序带来灾难性的打击,这些正是编写多线程程序时最需要注意的地方。 | ||
|
||
除了以上所说的优点外,不和进程比较,多线程程序作为一种多任务、并发的工作方式,天然有以下的优点: | ||
|
||
- 提高应用程序响应。这对图形界面的程序尤其有意义,当一个操作耗时很长时,整个系统都会等待这个操作,此时程序不会响应键盘、鼠标、菜单的操作,而使用多线程技术,将耗时长的操作(time consuming)置于一个新的线程,可以避免这种尴尬的情况。 | ||
- 使多CPU系统更加有效。操作系统会保证当线程数不大于CPU数目时,不同的线程运行于不同的CPU上。 | ||
- 改善程序结构。一个既长又复杂的进程可以考虑分为多个线程,成为几个独立或半独立的运行部分,这样的程序会利于理解和修改。 | ||
|
||
对比说明 | ||
========== | ||
|
||
从函数调用上来说,进程创建使用 ``fork()`` 操作;线程创建使用 ``clone()`` 操作。 | ||
|
||
Richard Stevens大师这样说过(大意): | ||
|
||
- fork开销很大,内存从父进程复制到子进程,所有的描述符都需要在子进程复制,以此类推。目前fork的实现使用一种 **写时复制** 的技术,该技术避免将父进程的数据空间复制到子进程,直到子进程需要自己的副本。但是不论怎样优化,fork都是昂贵的开销 | ||
- 在fork之后,父进程和子进程之间的通信需要采用IPC(进程间通讯): 在fork之前父进程传递给子进程信息非常容易,这是因为子进程从父进程数据空间复制了一个副本,并且也复制了所有父进程的描述符。但是反过来,子进程要向父进程返回信息就需要大量的工作。 | ||
|
||
线程有助于解决上述2个问题: | ||
|
||
- 线程有时候被称为轻量级进程,线程的创建速度比进程创建快10到100倍 | ||
- 一个进程的所有线程共享相同的全局内存,这使得线程间信息共享很容易,但是这种简单性带来的问题是同步问题 | ||
|
||
参考 | ||
====== | ||
|
||
- `Linux多线程编程(不限Linux) <http://www.cnblogs.com/skynet/archive/2010/10/30/1865267.html>`_ | ||
- `Linux 线程实现机制分析 <https://www.ibm.com/developerworks/cn/linux/kernel/l-thread/>`_ | ||
- `Linux 线程模型的比较:LinuxThreads 和 NPTL <http://www.ibm.com/developerworks/cn/linux/l-threading.html>`_ | ||
- `知乎:Linux中进程和线程的开销基本一样啊,为什么还要多线程呢? <https://www.zhihu.com/question/19903801>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.. _thread_count: | ||
|
||
==================== | ||
线程数量统计 | ||
==================== | ||
|
||
快速起步 | ||
========== | ||
|
||
在系统监控时,我们需要关注一个进程的线程数量以及操作系统的线程总量,可以采用如下简便的方法: | ||
|
||
- 获取一个指定 ``pid`` 的所有线程数量: | ||
|
||
.. literalinclude:: thread_count/ps_pid_thread | ||
:caption: 获取指定pid的所有线程的数量 | ||
|
||
注意,这里会直接返回一个进程的所有线程总数(直接返回数字),原因是这里参数 ``nlwp`` 表示 ``Number of LightWeight Processes`` ,也就是线程数量 | ||
|
||
举例 我的 :ref:`kvm` 虚拟机 ``z-b-data-1`` 的进程PID是 ``7410`` ,则可以通过以下命令检查:: | ||
|
||
ps -o nlwp 7410 | ||
|
||
输出结果:: | ||
|
||
9 | ||
|
||
表明有9个线程 | ||
|
||
其实,这个线程数量可以从 ``/proc/<pid>/status`` 中查看:: | ||
|
||
cat /proc/7410/status | ||
|
||
输出案例: | ||
|
||
.. literalinclude:: thread_count/proc_status_output | ||
:caption: 检查进程对应的状态(线程数量) | ||
:emphasize-lines: 35 | ||
|
||
- 获取整个操作系统的线程数量(非常有用的监控命令): | ||
|
||
.. literalinclude:: thread_count/linux_os_threads_number | ||
:caption: 获取Linux操作系统所有线程总数 | ||
|
||
参考 | ||
===== | ||
|
||
- `How to get (from terminal) total number of threads (per process and total for all processes) <https://askubuntu.com/questions/88972/how-to-get-from-terminal-total-number-of-threads-per-process-and-total-for-al>`_ | ||
- `Thread count of a process in Linux <https://www.site24x7.com/learn/linux/linux-threads.html#:~:text=This%20is%20found%20in%20the,threads%20created%20for%20a%20process.>`_ 这篇文章更为详细,待学习 | ||
- `Maximum Number of Threads per Process in Linux <https://www.baeldung.com/linux/max-threads-per-process#:~:text=How%20to%20Retrieve%20Maximum%20Thread,%2Fkernel%2Fthreads%2Dmax.&text=Here%2C%20the%20output%2063704%20indicates,a%20maximum%20of%2063%2C704%20threads.>`_ 操作系统对每个进程的线程数量是有限制的 | ||
- `Maximum number of threads per process in Linux? <https://stackoverflow.com/questions/344203/maximum-number-of-threads-per-process-in-linux>`_ | ||
- `Solved: Check thread count per process in Linux [5 Methods] <https://www.golinuxcloud.com/check-threads-per-process-count-processes/>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Name: qemu-system-x86 | ||
Umask: 0002 | ||
State: S (sleeping) | ||
Tgid: 7410 | ||
Ngid: 7418 | ||
Pid: 7410 | ||
PPid: 1 | ||
TracerPid: 0 | ||
Uid: 64055 64055 64055 64055 | ||
Gid: 108 108 108 108 | ||
FDSize: 128 | ||
Groups: 20 108 64055 | ||
NStgid: 7410 | ||
NSpid: 7410 | ||
NSpgid: 7409 | ||
NSsid: 7409 | ||
VmPeak: 17678804 kB | ||
VmSize: 17675976 kB | ||
VmLck: 16777088 kB | ||
VmPin: 0 kB | ||
VmHWM: 16838564 kB | ||
VmRSS: 16825184 kB | ||
RssAnon: 16805424 kB | ||
RssFile: 19756 kB | ||
RssShmem: 4 kB | ||
VmData: 17135716 kB | ||
VmStk: 136 kB | ||
VmExe: 6084 kB | ||
VmLib: 13916 kB | ||
VmPTE: 33600 kB | ||
VmSwap: 0 kB | ||
HugetlbPages: 0 kB | ||
CoreDumping: 0 | ||
THP_enabled: 1 | ||
Threads: 9 | ||
SigQ: 0/1546799 | ||
SigPnd: 0000000000000000 | ||
ShdPnd: 0000000000000000 | ||
SigBlk: 0000000010002240 | ||
SigIgn: 0000000000001000 | ||
SigCgt: 0000000100004243 | ||
CapInh: 0000000000000000 | ||
CapPrm: 0000000000000000 | ||
CapEff: 0000000000000000 | ||
CapBnd: 000001ffffffffff | ||
CapAmb: 0000000000000000 | ||
NoNewPrivs: 1 | ||
Seccomp: 2 | ||
Seccomp_filters: 1 | ||
Speculation_Store_Bypass: thread force mitigated | ||
SpeculationIndirectBranch: conditional force disabled | ||
Cpus_allowed: ffff,ffffffff | ||
Cpus_allowed_list: 0-47 | ||
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000003 | ||
Mems_allowed_list: 0-1 | ||
voluntary_ctxt_switches: 32359118 | ||
nonvoluntary_ctxt_switches: 66982 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ps -o nlwp <pid> |
4 changes: 2 additions & 2 deletions
4
source/kubernetes/arm/arm_k8s.rst → source/kubernetes/arm/arm_k8s_plan.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
source/kubernetes/concepts/configuration/taints_and_tolerations/get_nodes_taints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kubectl get nodes -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect |
1 change: 1 addition & 0 deletions
1
source/kubernetes/concepts/configuration/taints_and_tolerations/taint_dedicated_group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kubectl taint nodes nodename dedicated=groupName:NoSchedule |
1 change: 1 addition & 0 deletions
1
source/kubernetes/concepts/configuration/taints_and_tolerations/taint_special_hardware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kubectl taint nodes nodename special=true:NoSchedule |
23 changes: 23 additions & 0 deletions
23
source/kubernetes/monitor/grafana/grafana_behind_reverse_proxy_sub-path.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. _grafana_behind_reverse_proxy_sub-path: | ||
|
||
======================================= | ||
在反向代理后面运行Grafana (sub-path) | ||
======================================= | ||
|
||
在配合 :ref:`prometheus_startup_centos7` ,也采用了相似的 ``sub-path`` 反向代理: | ||
|
||
- 在 :ref:`install_grafana` 完成后,对于反向代理,需要修订 ``/etc/grafana/grafana.ini`` 配置文件: | ||
|
||
- 访问域名 ``domain`` | ||
- 访问url ``root_url`` | ||
|
||
配置修订位于 ``[server]`` 部分如下: | ||
|
||
.. literalinclude:: grafana_behind_reverse_proxy_sub-path/grafana.ini | ||
:caption: 修订 ``/etc/grafana/grafana.ini`` 配置访问域名以及访问路径 | ||
|
||
|
||
- 在NGINX服务器上 配置 ``/etc/nginx/conf.d/onesre-core.conf`` 设置反向代理: | ||
|
||
.. literalinclude:: grafana_behind_reverse_proxy_sub-path/sub-path_nginx.conf | ||
:caption: nginx反向代理,grafana用sub-path模式 ``/etc/nginx/conf.d/onesre-core.conf`` |
4 changes: 4 additions & 0 deletions
4
source/kubernetes/monitor/grafana/grafana_behind_reverse_proxy_sub-path/grafana.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[server] | ||
domain = onesre.cloud-atlas.io | ||
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/ | ||
serve_from_sub_path = true |
14 changes: 14 additions & 0 deletions
14
source/kubernetes/monitor/grafana/grafana_behind_reverse_proxy_sub-path/sub-path_nginx.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
upstream grafana { | ||
server 192.168.8.151:3000; | ||
} | ||
|
||
server { | ||
listen 80; | ||
|
||
server_name onesre onesre.cloud-atlas.io; | ||
|
||
location / { | ||
include proxy_params; | ||
proxy_pass http://grafana; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
source/kubernetes/monitor/grafana/install_grafana_centos7.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.. _install_grafana_centos7: | ||
|
||
===================== | ||
CentOS 7安装Grafana | ||
===================== | ||
|
||
.. note:: | ||
|
||
和 :ref:`prometheus_startup_centos7` 一样,在生产环境CentOS 7操作系统上部署Grafana。实践验证,实际上安装步骤和 :ref:`install_grafana` 一致,原因是Grafana提供了非常完善的软件仓库,支持CentOS 7系列。本文实践中添加了 ``sub-path`` :ref:`grafana_behind_reverse_proxy` 配置部分 | ||
|
||
在CentOS7上安装 | ||
==================== | ||
|
||
安装方法和 RHEL/Fedora 没有区别: | ||
|
||
- 添加仓库GPG密钥以及创建仓库配置文件: | ||
|
||
.. literalinclude:: install_grafana/rhel_install_grafana | ||
:caption: 在RHEL/Fedora上安装Grafana | ||
|
||
- 启动服务(和Debian/Ubuntu相同): | ||
|
||
.. literalinclude:: install_grafana/ubuntu_start_grafana | ||
:caption: 启动Grafana | ||
|
||
|
||
|
||
参考 | ||
===== | ||
|
||
- `Install on Debian or Ubuntu <https://grafana.com/docs/grafana/latest/installation/debian/>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.