一、使用 nginx 实现 灰度发布
灰度发布,现在是很多大项目的一个标配运维特性,我们可以将一个“新的版本代码”发布到集群中的少数几台(组)机器上,以便引入线上少量真实用
户进行测试,用于验证产品改进的收益、小规模试错等。nginx提供了“nginx_http_split_clients_module”、“nginx_stream_split_clients_module”,
分别适用于http和tcp,可以帮助我们简单实现这些功能。
http { split_clients "${remote_addr}AAA" $variant { 0.5% .one; 2.0% .two; * ""; } server { location / { index index${variant}.html;
二、工作进程数设置
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数
# 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数
# 查看物理CPU个数
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
# 查看每个物理CPU中core的个数(即核数)
cat /proc/cpuinfo| grep "cpu cores"| uniq
# 查看逻辑CPU的个数
cat /proc/cpuinfo| grep "processor"| wc -l
Binds worker processes to the sets of CPUs. Each CPU set is represented by a bitmask of allowed CPUs.
There should be a separate set defined for each of the worker processes.
By default, worker processes are not bound to any specific CPUs.
For example,
worker_processes 4; worker_cpu_affinity 0001 0010 0100 1000;
binds each worker process to a separate CPU, while
worker_processes 2; worker_cpu_affinity 0101 1010;
binds the first worker process to CPU0/CPU2, and the second worker process to CPU1/CPU3. The second example is suitable for hyper-threading.
The special value auto
(1.9.10) allows binding worker processes automatically to available CPUs:
worker_processes auto; worker_cpu_affinity auto;
The optional mask parameter can be used to limit the CPUs available for automatic binding:
worker_cpu_affinity auto 01010101;