[20191118]确定linux服务器cpu数量.txt
--//链接http://www.itpub.net/thread-2121531-1-1.html上的讨论.
--//当时看到dbwN很多,猜测CPU数量一定很多。
--//我记忆里第一次见到一台compaq服务器N年之前,当时是开盖状态,开机那个噪声让我至今难忘。
--//想起我工作中一次难堪,20113年单位要对每台服务器登记存档,因为服务器很多,每个人负责一部分。
--//数据库服务器当然数据库组负责。当时我一直以为cpu数量就是2,4,8,16,32数量。
--//当我检查才发现,其中一台服务器CPU数量是24,当时的感觉自己是不是看错了。
--//总结一下如何确定linux服务器cpu数量的方法。
1.检查/proc/cpuinfo:
# cat /proc/cpuinfo | grep -i processor|wc -l
24
# cat /proc/cpuinfo | grep -i cores| uniq
cpu cores : 6
# grep '^core id' /proc/cpuinfo | sort -u
core id : 0
core id : 1
core id : 2
core id : 3
core id : 4
core id : 5
--//逻辑cpu数量是24,6个core.
--//实际上2个物理CPU,每个CPU有6个core,打开超线程就是24个逻辑cpu.
2.使用dmicode:
# dmidecode -t 4
# dmidecode 2.11
SMBIOS 2.8 present.
# SMBIOS implementations newer than version 2.7 are not
# fully supported by this version of dmidecode.
Handle 0x0400, DMI type 4, 42 bytes
Processor Information
Socket Designation: Proc 1
Type: Central Processor
Family: Xeon
Manufacturer: Intel
ID: E4 06 03 00 FF FB EB BF
Signature: Type 0, Family 6, Model 62, Stepping 4
Flags:
FPU (Floating-point unit on-chip)
VME (Virtual mode extension)
DE (Debugging extension)
PSE (Page size extension)
TSC (Time stamp counter)
MSR (Model specific registers)
PAE (Physical address extension)
MCE (Machine check exception)
CX8 (CMPXCHG8 instruction supported)
APIC (On-chip APIC hardware supported)
SEP (Fast system call)
MTRR (Memory type range registers)
PGE (Page global enable)
MCA (Machine check architecture)
CMOV (Conditional move instruction supported)
PAT (Page attribute table)
PSE-36 (36-bit page size extension)
CLFSH (CLFLUSH instruction supported)
DS (Debug store)
ACPI (ACPI supported)
MMX (MMX technology supported)
FXSR (FXSAVE and FXSTOR instructions supported)
SSE (Streaming SIMD extensions)
SSE2 (Streaming SIMD extensions 2)
SS (Self-snoop)
HTT (Multi-threading)
TM (Thermal monitor supported)
PBE (Pending break enabled)
Version: Intel(R) Xeon(R) CPU E5-2630 v2 @ 2.60GHz
Voltage: 1.4 V
External Clock: 100 MHz
Max Speed: 4800 MHz
Current Speed: 2600 MHz
Status: Populated, Enabled
Upgrade:
L1 Cache Handle: 0x0710
L2 Cache Handle: 0x0720
L3 Cache Handle: 0x0730
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Core Count: 6
Core Enabled: 6
Thread Count: 12
Characteristics:
64-bit capable
Handle 0x0401, DMI type 4, 42 bytes
Processor Information
Socket Designation: Proc 2
Type: Central Processor
Family: Xeon
Manufacturer: Intel
ID: E4 06 03 00 FF FB EB BF
Signature: Type 0, Family 6, Model 62, Stepping 4
Flags:
FPU (Floating-point unit on-chip)
VME (Virtual mode extension)
DE (Debugging extension)
PSE (Page size extension)
TSC (Time stamp counter)
MSR (Model specific registers)
PAE (Physical address extension)
MCE (Machine check exception)
CX8 (CMPXCHG8 instruction supported)
APIC (On-chip APIC hardware supported)
SEP (Fast system call)
MTRR (Memory type range registers)
PGE (Page global enable)
MCA (Machine check architecture)
CMOV (Conditional move instruction supported)
PAT (Page attribute table)
PSE-36 (36-bit page size extension)
CLFSH (CLFLUSH instruction supported)
DS (Debug store)
ACPI (ACPI supported)
MMX (MMX technology supported)
FXSR (FXSAVE and FXSTOR instructions supported)
SSE (Streaming SIMD extensions)
SSE2 (Streaming SIMD extensions 2)
SS (Self-snoop)
HTT (Multi-threading)
TM (Thermal monitor supported)
PBE (Pending break enabled)
Version: Intel(R) Xeon(R) CPU E5-2630 v2 @ 2.60GHz
Voltage: 1.4 V
External Clock: 100 MHz
Max Speed: 4800 MHz
Current Speed: 2600 MHz
Status: Populated, Idle
Upgrade:
L1 Cache Handle: 0x0716
L2 Cache Handle: 0x0726
L3 Cache Handle: 0x0736
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Core Count: 6
~~~~~~~~~~~~~~~
Core Enabled: 6
~~~~~~~~~~~~~~~~
Thread Count: 12
~~~~~~~~~~~~~~~~~
Characteristics:
64-bit capable
--//注意看下划线.
# getconf _NPROCESSORS_ONLN
24
3.使用lscpu:
--//我的测试环境没有安装,找另外一台机器观察:
# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 8
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
Stepping: 1
CPU MHz: 2096.494
BogoMIPS: 4195.14
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 20480K
NUMA node0 CPU(s): 0-7
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse
sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc eagerfpu
pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand
hypervisor lahf_lm abm 3dnowprefetch arat invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm
rdseed adx smap xsaveopt
--//感觉lscpu显示更加直观一些.
# cat /proc/cpuinfo | grep -i processor|wc -l
8
# cat /proc/cpuinfo | grep -i cores| uniq
cpu cores : 1
--//不知道是否这台机器没有打开超线程.
4.补充一些其它cpu相关知识:
--//taskset - retrieve or set a processes's CPU affinity
# ps -ef | grep tnslsn[r]
oracle 22995 1 0 Nov11 ? 00:00:15 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
# taskset -p 22995
pid 22995's current affinity mask: ffffff
--//f 表示二进制 1111.就是可以在24个cpu资源.
# taskset -p ff 22995
pid 22995's current affinity mask: ffffff
pid 22995's new affinity mask: ff
--//这样相当于使用8个cpu资源.
# taskset -p 22995
pid 22995's current affinity mask: ff
--//如果你远程登录连接数据库,这样对应进程也仅仅能使用前面8个逻辑cpu资源.
SCOTT@78> @ spid
SID SERIAL# PROCESS SERVER SPID PID P_SERIAL# C50
---------- ---------- ------------------------ --------- -------------------- ------- ---------- --------------------------------------------------
90 1903 6964:3344 DEDICATED 29167 30 29 alter system kill session '90,1903' immediate;
# taskset -p 29167
pid 29167's current affinity mask: ff
--//还原.
# taskset -p ffffff 22995
pid 22995's current affinity mask: ff
pid 22995's new affinity mask: ffffff
5.你可以通过修改内核参数关闭一些cpu资源:
# seq 0 23 | xargs -I {} bash -c "echo -n cpu{}: ;cat /sys/devices/system/cpu/cpu{}/online"
cpu0:cat: /sys/devices/system/cpu/cpu0/online: No such file or directory
cpu1:1
cpu2:1
cpu3:1
cpu4:1
cpu5:1
cpu6:1
cpu7:1
cpu8:1
cpu9:1
cpu10:1
cpu11:1
cpu12:1
cpu13:1
cpu14:1
cpu15:1
cpu16:1
cpu17:1
cpu18:1
cpu19:1
cpu20:1
cpu21:1
cpu22:1
cpu23:1
--//cpu0没有online.设置online=0就可以实现cpu的hotplug.
# echo 0 >| /sys/devices/system/cpu/cpu23/online
# seq 0 23 | xargs -I {} bash -c "echo -n cpu{}: ;cat /sys/devices/system/cpu/cpu{}/online"
cpu0:cat: /sys/devices/system/cpu/cpu0/online: No such file or directory
cpu1:1
cpu2:1
cpu3:1
cpu4:1
cpu5:1
cpu6:1
cpu7:1
cpu8:1
cpu9:1
cpu10:1
cpu11:1
cpu12:1
cpu13:1
cpu14:1
cpu15:1
cpu16:1
cpu17:1
cpu18:1
cpu19:1
cpu20:1
cpu21:1
cpu22:1
cpu23:0
# ps -ef | grep tnslsn[r]
oracle 22995 1 0 Nov11 ? 00:00:16 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit
# taskset -p 22995
pid 22995's current affinity mask: 7fffff
--//可以发现mask变成了7fffff,也就是cpu23对应第1位.如果你使用top按1,可以发现仅仅显示到cpu22.
SCOTT@78> @ spid
SID SERIAL# PROCESS SERVER SPID PID P_SERIAL# C50
---------- ---------- ------------------------ --------- -------------------- ------- ---------- --------------------------------------------------
90 1907 2376:7848 DEDICATED 31055 30 31 alter system kill session '90,1907' immediate;
--//如果你重启数据库看到的cpu_count是23
ORACLE instance started.
Total System Global Area 643084288 bytes
Fixed Size 2255872 bytes
Variable Size 205521920 bytes
Database Buffers 427819008 bytes
Redo Buffers 7487488 bytes
Database mounted.
Database opened.
SYS@book> show parameter cpu_count
NAME TYPE VALUE
--------- ------- -----
cpu_count integer 23
# taskset -p 31055
pid 31055's current affinity mask: 7fffff
--//还原:
# echo 1 >| /sys/devices/system/cpu/cpu23/online
# taskset -p 22995
pid 22995's current affinity mask: ffffff
6.测试cpu性能:
--//测试cpu性能方法很多,我自己的方法就是使用bc计算器.
# time echo 2^1000000 | bc > /dev/null
real 0m4.116s
user 0m4.100s
sys 0m0.008s
--//这样即简单又快捷,仅仅作为一个参考.记住1后面是6个0.目前我的测试基本在4秒多1点.