[20191118]確定linux伺服器cpu數量.txt

lfree發表於2019-11-18

[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: <OUT OF SPEC>
        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: <OUT OF SPEC>
        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點.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2664551/,如需轉載,請註明出處,否則將追究法律責任。

相關文章