### LVM Performance Tuning and Display Commands Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/17/index.html This section provides examples of LVM commands used to display logical volume information, including stripe size and number of stripes. These commands are useful for understanding and optimizing LVM performance, particularly in multi-disk configurations. The examples show how to view segment details and physical volume mappings. ```bash #lvs -o +lv_full_name,devices,stripe_size,stripes # lvs -v --segments # lvdisplay -m ``` -------------------------------- ### Bash Script: Disk Partitioning and LVM Setup Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/17/index.html This script performs disk partitioning and sets up LVM logical volumes. It takes an action and a list of disk devices as arguments. It removes existing partitions, clears partition tables, configures LVM, creates logical volumes with specific stripe sizes, formats the filesystem, and updates fstab. It includes error handling for incorrect arguments. ```bash function disk_part(){ set -e if [ $# -le 1 ] then echo "disk_part argument error" exit -1 fi action=$1 disk_device_list=(`echo $*`) echo $disk_device_list unset disk_device_list[0] echo $action echo ${disk_device_list[*]}) len=`echo ${#disk_device_list[@]}` echo "start remove origin partition " for dev in ${disk_device_list[@]} do #echo ${dev} `parted -s ${dev} rm 1` || true dd if=/dev/zero of=${dev} count=100000 bs=512 done #替换98行,插入的话r改成a sed -i "98 r\ types = ['aliflash' , 252 , 'nvme' ,252 , 'venice', 252 , 'aocblk', 252]" /etc/lvm/lvm.conf sed -i "/flash/d" /etc/fstab if [ x${1} == x"split" ] then echo "split disk " #lvmdiskscan echo ${disk_device_list} #vgcreate -s 32 vgpolarx /dev/nvme0n1 /dev/nvme2n1 vgcreate -s 32 vgpolarx ${disk_device_list[*]} #stripesize 16K 和MySQL pagesize适配 #lvcreate -A y -I 16K -l 100%FREE -i 2 -n polarx vgpolarx lvcreate -A y -I 16K -l 100%FREE -i ${#disk_device_list[@]} -n polarx vgpolarx #lvcreate -A y -I 128K -l 75%VG -i ${len} -n volume1 vgpolarx #lvcreate -A y -I 128K -l 100%FREE -i ${len} -n volume2 vgpolarx mkfs.ext4 /dev/vgpolarx/polarx -m 0 -O extent,uninit_bg -E lazy_itable_init=1 -q -L polarx -J size=4000 sed -i "/polarx/d" /etc/fstab mkdir -p /polarx opt="defaults,noatime,data=writeback,nodiratime,nodelalloc,barrier=0" echo "LABEL=polarx /polarx ext4 ${opt} 0 0" >> /etc/fstab mount -a else echo "unkonw action " fi } ``` -------------------------------- ### Bash Script: Format NVMe Drives and Setup LVM Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/17/index.html This script is designed to format NVMe drives and set up Logical Volume Management (LVM). It first checks existing partitions, unmounts them if necessary, identifies available NVMe devices, and then calls the `disk_part` function to perform the LVM setup. It ensures that the LVM setup is only performed if the target mount point '/polarx' does not already exist. ```bash function format_nvme_mysql(){ if [ `df |grep flash|wc -l` -eq $1 ] then echo "check success" echo "start umount partition " parttion_list=`df |grep flash|awk -F ' ' '{print $1}'` for partition in ${parttion_list[@]} do echo $partition umount $partition done else echo "check host fail" exit -1 fi disk_device_list=(`ls -l /dev/|grep -v ^l|awk '{print $NF}'|grep -E "^nvme[0-9]{1,2}n1$|^df[a-z]$|^os[a-z]$"`) full_disk_device_list=() for i in ${!disk_device_list[@]} do echo ${i} full_disk_device_list[${i}]=/dev/${disk_device_list[${i}]} done echo ${full_disk_device_list[@]} disk_part split ${full_disk_device_list[@]} } if [ ! -d "/polarx" ]; then umount /dev/vgpolarx/polarx vgremove -f vgpolarx dmsetup --force --retry --deferred remove vgpolarx-polarx format_nvme_mysql $1 else echo "the lvm exists." fi ``` -------------------------------- ### Network Interface Configuration Example Source: https://github.com/plantegg/plantegg.github.io/blob/master/2016/03/24/ansible 命令通道使用手册/index.html This snippet shows the configuration details for a network interface, including its MAC address, IP address, netmask, and network address. It also details features like promiscuous mode and timestamping. ```json { "macaddress": "00:16:3e:2c:a2:c2", "module": "virtio_net", "mtu": 1500, "pciid": "virtio4", "promisc": false, "timestamping": [ "rx_software", "software" ], "type": "ether" } ``` -------------------------------- ### Run Ansible Playbook on Specific IP Address Source: https://github.com/plantegg/plantegg.github.io/blob/master/2016/03/24/ansible 命令通道使用手册/index.html This example shows how to execute an Ansible playbook against a single specified IP address. It uses the '-i' flag to define the inventory, pointing to a single IP address, followed by the target hosts (in this case, 'all' which will resolve to the specified IP) and the playbook file name. This is useful for targeted deployments or configurations. ```ansible ansible-playbook -i “10.168.101.179,” all test.yml ``` -------------------------------- ### TCP Connection Endpoint Details Source: https://github.com/plantegg/plantegg.github.io/blob/master/2020/11/30/一台机器上最多能创建多少个TCP连接/index.html This C code snippet illustrates the creation of a TCP socket and the setup of a remote address structure. It shows how to specify the remote IP address and port for a connection. The code is part of a larger example likely intended to explore ephemeral port allocation during the connection process. ```c #include #include #include #include #include void sample() { // Create socket int sockfd; if (sockfd = socket(AF_INET, SOCK_STREAM, 0), -1 == sockfd) { perror("socket"); } // Connect to remote. This does NOT actually send a packet. const struct sockaddr_in raddr = { .sin_family = AF_INET, .sin_port = htons(8080), // arbitrary remote port // ... potentially other fields like sin_addr ... }; // ... rest of the code ... close(sockfd); } ``` -------------------------------- ### FIO Configuration and Randread Test Source: https://github.com/plantegg/plantegg.github.io/blob/master/2022/01/25/ssd_san和sas磁盘性能比较/index.html This snippet shows the command-line arguments used to configure and run a FIO benchmark for EBS volumes. It specifies parameters like I/O engine, block size, direct I/O, buffering, threading, read/write mix, size, filename, I/O depth, and runtime. The output details the test setup and the performance results for a random read workload. ```bash [essd_pl3]# fio -ioengine=libaio -bs=4k -direct=1 -buffered=1 -thread -rw=randread -rwmixread=70 -size=160G -filename=./fio.test -name="EBS 4K randwrite test" -iodepth=64 -runtime=60 ``` ```text EBS 4K randwrite test: (g=0): rw=randread, bs=(R) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 fio-3.7 Starting 1 thread Jobs: 1 (f=1): [r(1)][100.0%][r=15.9MiB/s,w=0KiB/s][r=4058,w=0 IOPS][eta 00m:00s] EBS 4K randwrite test: (groupid=0, jobs=1): err= 0: pid=2441598: Thu Apr 7 17:05:10 2022 read: IOPS=3647, BW=14.2MiB/s (14.9MB/s)(855MiB/60001msec) slat (usec): min=183, max=10119, avg=239.01, stdev=110.20 clat (usec): min=2, max=54577, avg=15170.17, stdev=1324.10 lat (usec): min=237, max=55110, avg=15409.34, stdev=1338.09 clat percentiles (usec): | 1.00th=[13960], 5.00th=[14091], 10.00th=[14222], 20.00th=[14484], | 30.00th=[14615], 40.00th=[14746], 50.00th=[14877], 60.00th=[15139], | 70.00th=[15270], 80.00th=[15533], 90.00th=[16057], 95.00th=[16712], | 99.00th=[20317], 99.50th=[22152], 99.90th=[26346], 99.95th=[30802], | 99.99th=[52691] bw ( KiB/s): min= 6000, max=17272, per=100.00%, avg=16511.28, stdev=1140.64, samples=105 iops : min= 1500, max= 4318, avg=4127.81, stdev=285.16, samples=105 lat (usec) : 4=0.01%, 250=0.01%, 500=0.01%, 750=0.01%, 1000=0.01% lat (msec) : 2=0.01%, 4=0.01%, 10=0.01%, 20=98.91%, 50=1.05% lat (msec) : 100=0.02% cpu : usr=0.18%, sys=17.18%, ctx=219041, majf=0, minf=4215 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=100.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0% issued rwts: total=218835,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): READ:bw=14.2MiB/s (14.9MB/s), 14.2MiB/s-14.2MiB/s (14.9MB/s-14.9MB/s), io=855MiB (896MB), run=60001-60001msec Disk stats (read/write): vdb: ios=218343/7992, merge=0/8876, ticks=50566/3749, in_queue=54315, util=88.08% ``` -------------------------------- ### Format NVMe Drives for MySQL (Shell) Source: https://github.com/plantegg/plantegg.github.io/blob/master/2018/02/25/Linux LVM使用/index.html This script formats NVMe drives, preparing them for MySQL by calling the `disk_part` function. It first checks if the number of mounted 'flash' partitions matches the expected count, then unmounts them. It identifies NVMe devices and passes them to `disk_part` for LVM setup and formatting. It requires one argument: the expected number of 'flash' partitions. ```shell function format_nvme_mysql(){ if [ `df |grep flash|wc -l` -eq $1 ] then echo "check success" echo "start umount partition " parttion_list=`df |grep flash|awk -F ' ' '{print $1}'` for partition in ${parttion_list[@]} do echo $partition umount $partition done else echo "check host fail" exit -1 fi disk_device_list=(`ls -l /dev/|grep -v ^l|awk '{print $NF}'|grep -E "^nvme[0-9]{1,2}n1$|^df[a-z]$|^os[a-z]$ ``` -------------------------------- ### EBS 4K Randwrite Test Summary (libaio) Source: https://github.com/plantegg/plantegg.github.io/blob/master/2022/01/25/ssd_san和sas磁盘性能比较/index.html This snippet provides a summary of the EBS 4K random read/write test configuration and initial job information. It includes details on the I/O engine, block size, I/O depth, and the Fio version used. It also shows the start of the test execution with one thread. ```text EBS 4K randwrite test: (g=0): rw=randrw, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 fio-3.1 Starting 1 thread Jobs: 1 (f=1): [m(1)][100.0%][r=132KiB/s,w=148KiB/s][r=33,w=37 IOPS][eta 00m:00s] ``` -------------------------------- ### Get Socket Memory Information (C) Source: https://github.com/plantegg/plantegg.github.io/blob/master/2016/10/12/ss用法大全/index.html The `sk_get_meminfo` function populates a `u32` array with various memory statistics for a given socket. It initializes the array to zero and then retrieves values for received/sent buffer allocations, buffer sizes, forward allocation, queued memory, option memory, backlog length, and dropped packets. ```c void sk_get_meminfo(const struct sock *sk, u32 *mem) { memset(mem, 0, sizeof(*mem) * SK_MEMINFO_VARS); mem[SK_MEMINFO_RMEM_ALLOC] = sk_rmem_alloc_get(sk); mem[SK_MEMINFO_RCVBUF] = sk->sk_rcvbuf; mem[SK_MEMINFO_WMEM_ALLOC] = sk_wmem_alloc_get(sk); mem[SK_MEMINFO_SNDBUF] = sk->sk_sndbuf; mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc; mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued; mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc); mem[SK_MEMINFO_BACKLOG] = sk->sk_backlog.len; mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops); } ``` -------------------------------- ### Create Dummy Network Interface Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/17/index.html This section explains how to create a virtual network interface using the `dummy` kernel module. It involves loading the module if it's not already present and then using the `ip link add` command to create the interface. ```bash # Ensure the dummy kernel module is loaded: sudo lsmod | grep dummy sudo modprobe dummy sudo lsmod | grep dummy # Create a dummy network interface: sudo ip link add eth10 type dummy ``` -------------------------------- ### Configure IP Route with quickack Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/4/index.html This command configures an IP route for a specific subnet, setting the `quickack` option to 1 on the `eth0` interface. This is part of optimizing network behavior, potentially for faster acknowledgment of packets. ```bash #ip route change 172.16.0.0/24 dev eth0 quickack 1 ``` -------------------------------- ### Monitor Traffic with tsar (sendfile on, quickack on) Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/4/index.html This command uses `tsar` to monitor network traffic live with a 1-second interval, under conditions where `sendfile` is on and `quickack` is on. It displays traffic statistics, useful for evaluating the combined effect of these settings. ```bash #tsar --traffic -i1 --live Time ---------------------traffic-------------------- Time bytin bytout pktin pktout pkterr pktdrp 08/10/22-04:02:53 57.9M 158.7M 812.3K 1.2M 0.00 0.00 08/10/22-04:02:54 58.3M 159.6M 817.3K 1.2M 0.00 0.00 08/10/22-04:02:55 58.2M 159.4M 816.0K 1.2M 0.00 0.00 ``` -------------------------------- ### Display IP Routes Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/4/index.html This command displays the current IP routing table. It shows default routes, link-local routes, specific subnet routes with options like `quickack`, and routes for local network interfaces like `docker0`. ```bash #ip route default via 172.16.0.253 dev eth0 169.254.0.0/16 dev eth0 scope link metric 1002 172.16.0.0/24 dev eth0 scope link quickack 1 192.168.5.0/24 dev docker0 proto kernel scope link src 192.168.5.1 ``` -------------------------------- ### Bash Script: Partition and Format NVMe Drives for LVM Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/17/index.html This script partitions and formats NVMe drives, setting up LVM logical volumes. It handles disk preparation, LVM volume creation, filesystem formatting, and fstab updates. Dependencies include standard Linux utilities like parted, dd, sed, vgcreate, lvcreate, mkfs.ext4, and mount. ```bash function disk_part(){ set -e if [ $# -le 1 ] then echo "disk_part argument error" exit -1 fi action=$1 disk_device_list=(`echo $*`) echo $disk_device_list unset disk_device_list[0] echo $action echo ${disk_device_list[*]}) len=`echo ${#disk_device_list[@]}` echo "start remove origin partition " for dev in ${disk_device_list[@]} do #echo ${dev} `parted -s ${dev} rm 1` || true dd if=/dev/zero of=${dev} count=100000 bs=512 done #替换98行,插入的话r改成a sed -i "98 r\ types = ['aliflash' , 252 , 'nvme' ,252 , 'venice', 252 , 'aocblk', 252]" /etc/lvm/lvm.conf sed -i "/flash/d" /etc/fstab if [ x${1} == x"split" ] then echo "split disk " #lvmdiskscan echo ${disk_device_list} #vgcreate -s 32 vgpolarx /dev/nvme0n1 /dev/nvme2n1 vgcreate -s 32 vgpolarx ${disk_device_list[*]} #stripesize 16K 和MySQL pagesize适配 #lvcreate -A y -I 16K -l 100%FREE -i 2 -n polarx vgpolarx lvcreate -A y -I 16K -l 100%FREE -i ${#disk_device_list[@]} -n polarx vgpolarx #lvcreate -A y -I 128K -l 75%VG -i ${len} -n volume1 vgpolarx #lvcreate -A y -I 128K -l 100%FREE -i ${len} -n volume2 vgpolarx mkfs.ext4 /dev/vgpolarx/polarx -m 0 -O extent,uninit_bg -E lazy_itable_init=1 -q -L polarx -J size=4000 sed -i "/polarx/d" /etc/fstab mkdir -p /polarx opt="defaults,noatime,data=writeback,nodiratime,nodelalloc,barrier=0" echo "LABEL=polarx /polarx ext4 ${opt} 0 0" >> /etc/fstab mount -a else echo "unkonw action " fi } function format_nvme_mysql(){ if [ `df |grep flash|wc -l` -eq $1 ] then echo "check success" echo "start umount partition " parttion_list=`df |grep flash|awk -F ' ' '{print $1}'` for partition in ${parttion_list[@]} do echo $partition umount $partition done else echo "check host fail" exit -1 fi disk_device_list=(`ls -l /dev/|grep -v ^l|awk '{print $NF}'|grep -E "^nvme[0-9]{1,2}n1$|^df[a-z]$|^os[a-z]$"`) full_disk_device_list=() for i in ${!disk_device_list[@]} do echo ${i} full_disk_device_list[${i}]=/dev/${disk_device_list[${i}]} done echo ${full_disk_device_list[@]} disk_part split ${full_disk_device_list[@]} } if [ ! -d "/polarx" ]; then umount /dev/vgpolarx/polarx vgremove -f vgpolarx dmsetup --force --retry --deferred remove vgpolarx-polarx format_nvme_mysql $1 else echo "the lvm exists." fi ``` -------------------------------- ### Monitor Traffic with tsar (sendfile on, tcp_nopush on, quickack on) Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/4/index.html This command uses `tsar` to monitor network traffic live with a 1-second interval, under conditions where `sendfile` is on, `tcp_nopush` is on, and `quickack` is on. It displays traffic statistics for analysis. ```bash #tsar --traffic -i1 --live Time ---------------------traffic-------------------- Time bytin bytout pktin pktout pkterr pktdrp 08/10/22-03:27:23 40.7M 152.9M 452.6K 905.2K 0.00 0.00 08/10/22-03:27:24 40.7M 152.9M 452.6K 905.2K 0.00 0.00 08/10/22-03:27:25 40.6M 152.8M 452.3K 904.5K 0.00 0.00 08/10/22-03:27:26 40.6M 152.7M 452.1K 904.1K 0.00 0.00 08/10/22-03:27:27 40.6M 152.7M 452.0K 904.0K 0.00 0.00 08/10/22-03:27:28 40.7M 153.1M 453.2K 906.5K 0.00 0.00 ``` -------------------------------- ### Partition and Format NVMe Drives with LVM (Shell) Source: https://github.com/plantegg/plantegg.github.io/blob/master/2018/02/25/Linux LVM使用/index.html This script partitions and formats NVMe drives, creating a striped logical volume using LVM. It handles removing existing partitions, zeroing the disk, configuring LVM, creating a logical volume with specified stripe size, formatting it, and mounting it. It requires at least two arguments: the action ('split') and a list of disk devices. ```shell function disk_part(){ set -e if [ $# -le 1 ] then echo "disk_part argument error" exit -1 fi action=$1 disk_device_list=(`echo $*`) echo $disk_device_list unset disk_device_list[0] echo $action echo ${disk_device_list[*]}) len=`echo ${#disk_device_list[@]}` echo "start remove origin partition " for dev in ${disk_device_list[@]} do #echo ${dev} `parted -s ${dev} rm 1` || true dd if=/dev/zero of=${dev} count=100000 bs=512 done #替换98行,插入的话r改成a sed -i "98 r\ types = ['aliflash' , 252 , 'nvme' ,252 , 'venice', 252 , 'aocblk', 252]" /etc/lvm/lvm.conf sed -i "/flash/d" /etc/fstab if [ x${1} == x"split" ] then echo "split disk " #lvmdiskscan echo ${disk_device_list} #vgcreate -s 32 vgpolarx /dev/nvme0n1 /dev/nvme2n1 vgcreate -s 32 vgpolarx ${disk_device_list[*]}) #stripesize 16K 和MySQL pagesize适配 #lvcreate -A y -I 16K -l 100%FREE -i 2 -n polarx vgpolarx lvcreate -A y -I 16K -l 100%FREE -i ${#disk_device_list[@]} -n polarx vgpolarx #lvcreate -A y -I 128K -l 75%VG -i ${len} -n volume1 vgpolarx #lvcreate -A y -I 128K -l 100%FREE -i ${len} -n volume2 vgpolarx mkfs.ext4 /dev/vgpolarx/polarx -m 0 -O extent,uninit_bg -E lazy_itable_init=1 -q -L polarx -J size=4000 sed -i "/polarx/d" /etc/fstab mkdir -p /polarx opt="defaults,noatime,data=writeback,nodiratime,nodelalloc,barrier=0" echo "LABEL=polarx /polarx ext4 ${opt} 0 0" >> /etc/fstab mount -a else echo "unkonw action " fi } ``` -------------------------------- ### Observe TCP_NODELAY Socket Option with strace Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/4/index.html This snippet shows the use of `strace` to log `setsockopt` calls, specifically observing when the TCP_NODELAY option is set to 1 on a socket. This is useful for understanding socket-level configurations in network applications. ```bash #cat strace.log.88206 08:31:19.632581 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0 <0.000013> ``` -------------------------------- ### Run STREAM Benchmark with Varying CPU Cores (Shell) Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/5/index.html This shell script iterates through CPU core configurations from 0 to 255 with a step of 8, executing the STREAM benchmark for each configuration. It uses 'numactl' to control CPU affinity and memory allocation, and the STREAM benchmark tool with specified parameters for warm-up, number of runs, and memory size. The output captures latency and bandwidth for copy, scale, add, and triad operations. ```shell #!/bin/bash for i in $(seq 0 8 255); do echo $i; numactl -C $i -m 0 ./bin/stream -W 5 -N 5 -M 64M; done ``` -------------------------------- ### Run STREAM Benchmark with numactl Source: https://github.com/plantegg/plantegg.github.io/blob/master/2021/03/21/Intel AMD 鲲鹏 海光 飞腾性能PK/index.html This command executes the STREAM benchmark tool to measure memory bandwidth. It uses `numactl` to bind the process to specific CPU cores and memory nodes, allowing for performance analysis under different NUMA configurations. The loop iterates through CPU core assignments. ```bash time for i in $(seq 0 8 51); do echo $i; numactl -C $i -m 0 ./bin/stream -W 5 -N 5 -M 64M; done ``` -------------------------------- ### Create User with Password and Sudo Privileges using Ansible Playbook Source: https://github.com/plantegg/plantegg.github.io/blob/master/2016/03/24/ansible 命令通道使用手册/index.html This Ansible playbook defines tasks to create a user named 'ren' with a specified password and grant them sudo privileges. It uses the 'user' module to create the user and set their password (using a crypted hash) and the 'lineinfile' module to add the user to the sudoers file, allowing them to run commands as root. The playbook targets 'all' hosts and runs as the 'root' user. ```yaml - hosts: all user: root vars: # created with: # python -c 'import crypt; print crypt.crypt("password", "$1$SomeSalt$")' tasks: - name: create user ren with password user: name: ren password: "$1$SomeSalt$renpasswordhash" state: present shell: /bin/bash - name: allow ren to have root access lineinfile: dest: /etc/sudoers line: 'ren ALL=(ALL) NOPASSWD:ALL' state: present ``` -------------------------------- ### Run perf stat before sorting on aarch64 Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/4/index.html This command uses 'perf stat' to collect performance counters for the './beforesort' executable on an aarch64 processor. It measures events like branch misses, cache references, CPU cycles, and instruction counts. The output provides insights into the performance characteristics of the system before the sorting operation. ```bash #perf stat -e branch-misses,bus-cycles,cache-misses,cache-references,cpu-cycles,instructions,stalled-cycles-backend,stalled-cycles-frontend,alignment-faults,bpf-output,context-switches,cpu-clock,cpu-migrations,dummy,emulation-faults,major-faults,minor-faults,page-faults,task-clock,L1-dcache-load-misses,L1-dcache-loads,L1-icache-load-misses,L1-icache-loads,LLC-load-misses,LLC-loads,branch-load-misses,branch-loads,dTLB-load-misses,dTLB-loads,iTLB-load-misses,iTLB-loads ./beforesort 1.19468 sum = 314931600000 178,045 branch-misses (29.84%) 3,290,281,574 bus-cycles # 2748.321 M/sec (29.84%) 204,017,139 cache-misses # 24.768 % of all cache refs (29.84%) 823,700,482 cache-references # 688.024 M/sec (29.84%) 3,290,247,311 cpu-cycles # 2.748 GHz (34.85%) 5,730,855,778 instructions # 1.74 insn per cycle # 0.26 stalled cycles per insn (34.85%) 1,485,014,712 stalled-cycles-backend # 45.13% backend cycles idle (35.03%) 980,441 stalled-cycles-frontend # 0.03% frontend cycles idle (35.08%) 0 alignment-faults # 0.000 K/sec 0 bpf-output # 0.000 K/sec 2 context-switches # 0.002 K/sec 1,197.20 msec cpu-clock # 1.000 CPUs utilized 0 cpu-migrations # 0.000 K/sec 0 dummy # 0.000 K/sec 0 emulation-faults # 0.000 K/sec 0 major-faults # 0.000 K/sec 140 minor-faults # 0.117 K/sec 140 page-faults # 0.117 K/sec 1,197.20 msec task-clock # 1.000 CPUs utilized 205,399,817 L1-dcache-load-misses # 25.00% of all L1-dcache accesses (35.08%) 821,607,081 L1-dcache-loads # 686.276 M/sec (35.08%) 10,361 L1-icache-load-misses # 0.00% of all L1-icache accesses (35.08%) 1,150,511,080 L1-icache-loads # 961.004 M/sec (30.07%) 6,275 LLC-load-misses # 0.00% of all LL-cache accesses (30.07%) 0 LLC-loads # 0.000 K/sec (30.07%) 103,368 branch-load-misses # 0.086 M/sec (30.07%) 821,524,106 branch-loads # 686.206 M/sec (30.07%) 15,315 dTLB-load-misses # 0.00% of all dTLB cache accesses (30.07%) 821,589,564 dTLB-loads # 686.261 M/sec (30.07%) 1,084 iTLB-load-misses # 0.07% of all iTLB cache accesses (30.07%) 1,613,786 iTLB-loads # 1.348 M/sec (29.89%) ``` -------------------------------- ### Run STREAM Benchmark on Intel Xeon E5-2682 v4 Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/5/index.html This script executes the STREAM benchmark on an Intel Xeon E5-2682 v4 CPU, iterating through different core allocations (0, 8, 16, 24) using 'numactl'. It measures copy, scale, add, and triad operations, reporting latency and bandwidth for each. The script assumes the 'stream' executable is available in the './bin/' directory. ```bash #!/bin/bash for i in $(seq 0 8 51); do echo $i numactl -C $i -m 0 ./bin/stream -W 5 -N 5 -M 64M done ``` -------------------------------- ### View SSD Queue Depth (Bash) Source: https://github.com/plantegg/plantegg.github.io/blob/master/2022/01/25/ssd_san和sas磁盘性能比较/index.html This command uses `cat` to read the `nr_requests` file, which represents the queue depth for a given block device. This is useful for understanding how many I/O requests can be queued for a storage device. ```bash # cat /sys/block/nvme0n1/queue/nr_requests 1023 ``` ```bash # cat /sys/block/sdd/queue/nr_requests 128 ``` -------------------------------- ### Inspect Container Network Namespace with nsenter Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/17/index.html This snippet demonstrates how to use `nsenter` to execute commands within a specific network namespace, typically used for debugging container networking. It involves finding the SandboxKey for a pause container and then using `nsenter` with the `--net` flag to inspect network interfaces and statistics. ```bash # Get the pause container's sandboxkey: docker inspect k8s_POD_ubuntu-5846f86795-bcbqv_default_ea44489d-3dd4-11e8-bb37-02ecc586c8d5_0 | grep SandboxKey # Example output: # "SandboxKey": "/var/run/docker/netns/82ec9e32d486", # Now, using nsenter you can see the container's information: nsenter --net=/var/run/docker/netns/82ec9e32d486 ip addr show # Identify the peer_ifindex, and finally you can see the veth pair endpoint in root namespace: nsenter --net=/var/run/docker/netns/82ec9e32d486 ethtool -S eth0 # Example output for peer_ifindex: # peer_ifindex: 7 ip -d link show | grep '7: veth' # Alternative example using a different container ID: docker inspect cb7b05d82153 | grep -i SandboxKey # Example output: # "SandboxKey": "/var/run/docker/netns/d6b2ef3cf886", nsenter --net=/var/run/docker/netns/d6b2ef3cf886 ip addr show nsenter --net=/var/run/docker/netns/d6b2ef3cf886 ethtool -S eth0 ip -d -4 addr show cni0 ``` -------------------------------- ### Fio Configuration for EBS 4K Randwrite Test Source: https://github.com/plantegg/plantegg.github.io/blob/master/2022/01/25/ssd_san和sas磁盘性能比较/index.html This snippet shows the command-line arguments used to configure and run a fio test. It specifies the I/O engine, block size, direct I/O, buffering, read/write mix, test size, filename, test name, I/O depth, and runtime. ```bash # fio -ioengine=libaio -bs=4k -direct=1 -buffered=1 -thread -rw=randrw -rwmixread=70 -size=2G -filename=/var/lib/docker/fio.test -name="EBS 4K randwrite test" -iodepth=64 -runtime=60 ``` -------------------------------- ### Observe TCP_CORK Socket Option with strace Source: https://github.com/plantegg/plantegg.github.io/blob/master/page/4/index.html This snippet shows the use of `strace` to log `setsockopt` calls, observing when the TCP_CORK option is set to 1 and then cleared (set to 0) on a socket. TCP_CORK is used to queue non-full frames for transmission. ```bash #cat strace.log.85937 08:27:44.702111 setsockopt(3, SOL_TCP, TCP_CORK, [1], 4) = 0 <0.000011> 08:27:44.702353 setsockopt(3, SOL_TCP, TCP_CORK, [0], 4) = 0 <0.000013> ```