Linux 性能调优之虚拟化(Virtualization tuned)调优

写在前面


  • 考试整理相关笔记
  • 博文内容涉及Linux 虚拟化常见管理操作以及部分调优配置
  • 理解不足小伙伴帮忙指正

不必太纠结于当下,也不必太忧虑未来,当你经历过一些事情的时候,眼前的风景已经和从前不一样了。——村上春树


使用工具进行调优

可以直接使用 tuned 包里面的适用于虚拟化调优的参数,tuned 中对于虚拟化通过两个优化配置,一个适用虚拟机,一个适用虚拟机所在的宿主机。

- virtual-guest               - Optimize for running inside a virtual guest
- virtual-host                - Optimize for running KVM guests
  • virtual-guest:为运行在虚拟机客户机中进行优化,即虚拟机模式
  • virtual-host:为运行 KVM 客户机进行优化,运行了虚拟机的宿主机

看一下这个两个策略配置做了什么操作

虚拟机客户机策略,可以看到当前策略继承了下面的策略:

  • throughput-performance:最大吞吐量,提供磁盘和网络 IO 的吞吐量
┌──[root@liruilongs.github.io]-[~]
└─$cat /usr/lib/tuned/virtual-guest/tuned.conf
#
# tuned configuration
#[main]
summary=Optimize for running inside a virtual guest
include=throughput-performance[sysctl]
# If a workload mostly uses anonymous memory and it hits this limit, the entire
# working set is buffered for I/O, and any more write buffering would require
# swapping, so it's time to throttle writes until I/O can catch up.  Workloads
# that mostly use file mappings may be able to use even higher values.
#
# The generator of dirty data starts writeback at this percentage (system default
# is 20%)
vm.dirty_ratio = 30# Filesystem I/O is usually much more efficient than swapping, so try to keep
# swapping low.  It's usually safe to go even lower than this on systems with
# server-grade storage.
vm.swappiness = 30

修改了两个内核参数

vm.dirty_ratio = 30
vm.swappiness = 30

vm.dirty_ratio:这个参数指定了当匿名内存(anonymous memory)的脏页(dirty pages)达到一定比例时,开始进行写回(writeback)。脏页是指已经被修改但尚未写入磁盘的页面。默认值是20%,而在这个配置中设置为30%。当脏页达到这个比例时,系统会开始将这些数据写回磁盘,以便为后续的写入操作腾出空间。这个参数的增加可以延迟写回的触发,帮助提高I/O性能

vm.swappiness:这个参数控制系统在内存紧张时进行页面置换(swapping)的倾向程度。页面置换指的是将内存中的页面数据移出到交换空间(swap space)中,以便为其他进程或文件提供更多的内存空间。默认值是60,而在这个配置中设置为30。较低的值表示系统更倾向于使用文件系统的I/O操作来释放内存,而不是频繁进行页面置换。这对于使用高性能存储的服务器系统来说是安全的,可以降低页面置换的频率,提高整体性能。

虚拟机的宿主机策略,通过继承了 throughput-performance 最大吞吐量策略

┌──[root@liruilongs.github.io]-[~]
└─$cat /usr/lib/tuned/virtual-host/tuned.conf
#
# tuned configuration
#[main]
summary=Optimize for running KVM guests
include=throughput-performance[sysctl]
# Start background writeback (via writeback threads) at this percentage (system
# default is 10%)
vm.dirty_background_ratio = 5[cpu]
# Setting C3 state sleep mode/power savings
force_latency=cstate.id_no_zero:3|70
┌──[root@liruilongs.github.io]-[~]
└─$
  • vm.dirty_background_ratio:这个参数指定了当脏页的比例达到一定阈值时,系统开始后台写回(writeback)。脏页是指已经被修改但尚未写入磁盘的页面。默认值是10%,而在这个配置中设置为5%。当脏页达到这个比例时,系统会启动后台的写回线程,将部分数据写回磁盘,以减少内存中的脏页数量。通过降低这个阈值,可以在系统负载较轻时更早地开始后台写回,以提高整体的I/O性能。

  • [cpu] 部分中的 force_latency:这个配置参数用于设置CPU的C3状态(sleep mode)的睡眠模式或省电模式。C3状态是一种较深的睡眠状态,可以在CPU空闲时进入以节省能源。这里的配置 cstate.id_no_zero:3|70 指示系统在空闲时将CPU进入C3状态,以实现一定程度的省电。具体的值和配置方式可能因硬件和内核版本而有所不同,这里的示例是针对特定的设置。

vm.dirty_background_ratio 参数和 vm.dirty_ratio 参数的区别:

  • vm.dirty_background_ratio 用通俗的话讲,可以驻留在内存中最大占比,即这些数据要写到磁盘,但是这个这个阈值之内不会发生回写。

  • vm.dirty_ratio 用通俗的话讲,当前系统能允许的最大脏页占比。当系统到达这一点时,所有新的 I/O 都会阻塞,直到脏页已写入磁盘

资源占用信息查看

┌──[root@liruilongs.github.io]-[~]
└─$yum -y install numactl

numactl 是一个用于在 NUMA(非统一内存访问)系统上运行程序的实用工具。它可以帮助您管理和优化在 NUMA 架构下的内存访问和处理器分配。

NUMA(Non-Uniform Memory Access)是一种计算机系统架构,用于处理多处理器系统中的内存访问和内存管理。在NUMA架构中,系统中的内存被划分为多个节点(Node),每个节点与一个或多个处理器核心(CPU)相关联

每个NUMA节点包含一部分物理内存和与之关联的处理器核心。节点之间通过高速互连(如快速路径互连或片上互连)连接起来,以实现节点之间的通信和数据传输

使用numastat命令获取的关于qemu-kvm进程在不同NUMA节点上的内存使用情况的输出结果。

┌──[root@liruilongs.github.io]-[~]
└─$numastat -c qemu-kvmPer-node process memory usage (in MBs)
PID              Node 0 Total
---------------  ------ -----
1755 (qemu-kvm)     855   855
53693 (qemu-kvm)    759   759
53790 (qemu-kvm)   1218  1218
53890 (qemu-kvm)    875   875
54009 (qemu-kvm)    751   751
54128 (qemu-kvm)    811   811
54246 (qemu-kvm)    778   778
---------------  ------ -----
Total              6048  6048

设置虚拟机CPU绑定

使用 virsh 工具对虚拟机的虚拟CPU(VCPU)进行查看绑定操作

┌──[root@liruilongs.github.io]-[~]
└─$virsh vcpupin workstation
VCPU: CPU Affinity
----------------------------------0: 0-71: 0-7

指定了名为"workstation"的虚拟机的VCPU绑定情况。根据输出,该虚拟机有两个VCPU(标识符为0和1),并且它们都与CPU编号0到7之间的CPU核心有绑定关系。

┌──[root@liruilongs.github.io]-[~]
└─$virsh vcpupin servera
VCPU: CPU Affinity
----------------------------------0: 0-71: 0-7

对名为"serverc"的虚拟机的第一个VCPU(标识符为0)进行了更具体的绑定设置。它将该VCPU绑定到了CPU编号为0的核心上。

┌──[root@liruilongs.github.io]-[~]
└─$virsh vcpupin serverc 0 0
┌──[root@liruilongs.github.io]-[~]
└─$virsh vcpupin serverc
VCPU: CPU Affinity
----------------------------------0: 01: 0-7

0-5 表示将该 VCPU 绑定到 CPU 编号为 0到5的核心上。这意味着虚拟机的第一个VCPU只能在这些CPU核心上执行。

┌──[root@liruilongs.github.io]-[~]
└─$virsh vcpupin serverc 0 0-5┌──[root@liruilongs.github.io]-[~]
└─$virsh vcpupin serverc
VCPU: CPU Affinity
----------------------------------0: 0-51: 0-7

查看某个虚拟机的内存信息

┌──[root@liruilongs.github.io]-[~]
└─$virsh  dominfo workstation
Id:             3
Name:           workstation
UUID:           3f09a13c-94ad-4d97-8f76-17e9a81ae61f
OS Type:        hvm
State:          running
CPU(s):         2
CPU time:       771.0s
Max memory:     2097152 KiB #虚拟机可用的最大内存容量,以KiB(Kibibyte)为单位。
Used memory:    2097152 KiB #虚拟机当前使用的内存容量,以KiB为单位。
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:svirt_t:s0:c201,c330 (enforcing)

限制虚拟机的 CPU 资源

限制虚拟机的 CPU 资源, cpu shares=2048 的虚拟机会比cpu shares=1024 的虚拟机获得更多的 CPU 资源

┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$virsh schedinfo workstation
Scheduler      : posix
cpu_shares     : 1024
vcpu_period    : 100000
vcpu_quota     : -1
emulator_period: 100000
emulator_quota : -1
global_period  : 100000
global_quota   : -1
iothread_period: 100000
iothread_quota : -1┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$virsh schedinfo workstation cpu_shares=2048
Scheduler      : posix
cpu_shares     : 2048
vcpu_period    : 100000
vcpu_quota     : -1
emulator_period: 100000
emulator_quota : -1
global_period  : 100000
global_quota   : -1
iothread_period: 100000
iothread_quota : -1

虚拟机CPU份额(cpu shares)参数的值为2048。CPU份额用于确定虚拟机在竞争CPU资源时的优先级。较高的份额值表示虚拟机将获得更多的CPU时间片。

设置虚拟机内存限制

设置 control 虚拟机的最大内存容量(确保虚拟机关机状态设置

┌──[root@liruilongs.github.io]-[~]
└─$virsh setmaxmem workstation --size 2097152
error: Unable to change MaxMemorySize
error: Requested operation is not valid: cannot resize the maximum memory on an active domain

设置 control 虚拟机的运行内存容量(确保虚拟机开机状态设置)

┌──[root@liruilongs.github.io]-[~]
└─$virsh setmem workstation --size 2097152

查看虚拟机内存限制

┌──[root@liruilongs.github.io]-[~]
└─$virsh memtune workstation
hard_limit     : unlimited
soft_limit     : unlimited
swap_hard_limit: unlimited

设置虚拟机内存限制

┌──[root@liruilongs.github.io]-[~]
└─$virsh memtune workstation  --hard-limit 2G --soft-limit 1G
┌──[root@liruilongs.github.io]-[~]
└─$virsh memtune workstation
hard_limit     : 2097152
soft_limit     : 1048576
swap_hard_limit: unlimited┌──[root@liruilongs.github.io]-[~]
└─$

KSM 参数配置

多个虚拟机运行相同的操作系统或者工作负载时,许多内存也很可能具有相同的内容,对这些相同内存内存页进行合并称为内核共享内存(KSM)

当需要写入并修改共享内存时,KSM 会克隆共享页面,给虚拟机一个非共享的副本,这个过程称为写时复制(COW,copy on write)

ksm 进程: 执行内存扫描和内存页合并

┌──[root@liruilongs.github.io]-[~]
└─$systemctl status ksm
ksm.service       ksmtuned.service
┌──[root@liruilongs.github.io]-[~]
└─$systemctl status ksm.service
● ksm.service - Kernel Samepage MergingLoaded: loaded (/usr/lib/systemd/system/ksm.service; enabled; vendor preset: enabled)Active: active (exited) since Mon 2023-10-02 19:31:31 CST; 2 days agoMain PID: 997 (code=exited, status=0/SUCCESS)Tasks: 0 (limit: 253184)Memory: 0BCGroup: /system.slice/ksm.serviceOct 02 19:31:30 liruilongs.github.io systemd[1]: Starting Kernel Samepage Merging...
Oct 02 19:31:31 liruilongs.github.io systemd[1]: Started Kernel Samepage Merging.

ksmtuned 进程:控制何时扫描以及扫描的积极性

┌──[root@liruilongs.github.io]-[~]
└─$systemctl status ksmtuned.service
● ksmtuned.service - Kernel Samepage Merging (KSM) Tuning DaemonLoaded: loaded (/usr/lib/systemd/system/ksmtuned.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2023-10-02 19:31:36 CST; 2 days agoMain PID: 1036 (ksmtuned)Tasks: 2 (limit: 253184)Memory: 12.9MCGroup: /system.slice/ksmtuned.service├─ 1036 /bin/bash /usr/sbin/ksmtuned└─62516 sleep 60Oct 02 19:31:31 liruilongs.github.io systemd[1]: Starting Kernel Samepage Merging (KSM) Tuning Daemon...
Oct 02 19:31:36 liruilongs.github.io systemd[1]: Started Kernel Samepage Merging (KSM) Tuning Daemon.
┌──[root@liruilongs.github.io]-[~]
└─$

可以通过/sys/kerel/mm/ksm/目录下的参数,设置调优参数:

┌──[root@liruilongs.github.io]-[~]
└─$cat /sys/kernel/mm/ksm/
full_scans                          pages_to_scan                       stable_node_chains
max_page_sharing                    pages_unshared                      stable_node_chains_prune_millisecs
merge_across_nodes                  pages_volatile                      stable_node_dups
pages_shared                        run                                 use_zero_pages
pages_sharing                       sleep_millisecs
┌──[root@liruilongs.github.io]-[~]
└─$cat /sys/kernel/mm/ksm/run
0
┌──[root@liruilongs.github.io]-[~]
└─$
  • run:设置为 1 时,ksm 进程主动扫描内存,设置为 0 时,扫描被禁用。(默认为 0)
  • pages to scan:下一个周期要扫描的内存页数。(默认 100)sleep_millisecs:周期之间睡眠的时间,单位为毫秒。 (默认 20)
  • pages shared:共享总页数。 (默认 0)
  • pages_sharing:当前共享的页数。 (默认 0)
  • fullscans:扫描整个内存空间的次数。 (默认 0)
  • merge acrossnodes:是否合并不同 NUMA 节点的内存。(默认 1)

可以通过 virsh node-memory-tune 命令查看这些参数的值,或者修改这些参数文件的值.

nodecpustats      nodedev-destroy   nodedev-dumpxml   nodedev-list      nodedev-reset     node-memory-tune  nodesuspend
┌──[root@liruilongs.github.io]-[~]
└─$virsh node-memory-tune
Shared memory:shm_pages_to_scan 100shm_sleep_millisecs 20shm_pages_shared 2013shm_pages_sharing 5130shm_pages_unshared 10144shm_pages_volatile 91431shm_full_scans  28shm_merge_across_nodes 1┌──[root@liruilongs.github.io]-[~]
└─$virsh node-memory-tune --shm-sleep-millisecs 30┌──[root@liruilongs.github.io]-[~]
└─$virsh node-memory-tune
Shared memory:shm_pages_to_scan 100shm_sleep_millisecs 30shm_pages_shared 2013shm_pages_sharing 5130shm_pages_unshared 10144shm_pages_volatile 91431shm_full_scans  28shm_merge_across_nodes 1┌──[root@liruilongs.github.io]-[~]
└─$cat /sys/kernel/mm/ksm/sleep_millisecs
30
┌──[root@liruilongs.github.io]-[~]
└─$

虚拟磁盘配置调优

虚拟机使用的磁盘可以是一个块设备,也可以是一个镜像文件

直接使用块设备是一个不错的选择,而使用镜像文件则会带来额外的 I/O 资源需求,镜像文件需要更多的 I/0 资源, KVM 支持 2 种镜像格式:

  • raw
  • qcow2

raw 格式性能比 qcow2 更好,但是 qcow2 可以获得更多功能。qcow2 可以提供如下功能:

  • sparse image file (稀疏镜像文件或精简像文件,真正使用时才分配存储空间)
  • Cow(写时复制)
  • ROW (写时重定向),应用于快照
  • compression(支持压缩)
  • encryption(支持加密)
创建 qcow2 镜像

使用 gemu-img create 命令可以创建 qcow2 镜像文件:

┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$qemu-img create -f qcow2 -o preallocation=metadata /var/lib/libvirt/images/disk.qcow2 1G
Formatting '/var/lib/libvirt/images/disk.qcow2', fmt=qcow2 size=1073741824 cluster_size=65536 preallocation=metadata lazy_refcounts=off refcount_bits=16
┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$ll /var/lib/libvirt/images/disk.qcow2
-rw-r--r--. 1 root root 1074135040 Oct  5 14:17 /var/lib/libvirt/images/disk.qcow2
┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$

preallocation 支持的选择:

  • preallocation=off,不分配任何空间,off 为默认属性
  • preallocation=metadata,提前创建 metadata 空间,但不分配实际数据存储空间,快速创建镜像,但是写入速度会变慢。
  • preallocation=falloc,创建 metadata 空间和数据空间,但是标记 block 为未分配,创建镜像比 metadata 慢,但是写入速度更快
  • preallocation=full,创建镜像时分配所有资源,不使用 spare 技术。初始化镜像慢,性能类似 falloc。
创建快照盘(ROW)

基于 disk.qcow2 镜像文件,创建新的快照文件 disk-snap.qcow2,新像 30G

┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$qemu-img create -f qcow2 -b /var/lib/libvirt/images/disk.qcow2 disk-snap.qcow2 30G
Formatting 'disk-snap.qcow2', fmt=qcow2 size=32212254720 backing_file=/var/lib/libvirt/images/disk.qcow2 cluster_size=65536 lazy_refcounts=off refcount_bits=16
┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$ll /var/lib/libvirt/images/disk-snap.qcow2
-rw-r--r--. 1 root root 197088 Oct  5 14:25 /var/lib/libvirt/images/disk-snap.qcow2
┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$
虚拟机磁盘缓存模式
  • cache=none,不开启缓存,直接数据落盘,支持虚拟机迁移
  • cache=writethrough,数据同时写入缓存和物理硬盘,该选项确保数据完整性,但是写速度慢
  • cache=writeback,数据先写缓存,写入缓存及确认数据写入完成,然后缓存同步落盘
  • cache=directsync,类似 writethrouth,数据写入物理硬盘,需要的时候绕过缓存
  • cache=unsafe,类似于 writeback,但是所有 /O flush 都会被忽略,不确保数据安全,但是可以提升性能,比如在安装系统时使用该模式,但是不能应用在生产工作负载
┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$cat *.xml  | grep driver<driver name="qemu" type="qcow2" cache='none'/>

虚拟机磁盘 IO 调优

使用virsh blkdeviotune命令来为名为"workstation"的虚拟机的磁盘设备(vda)设置了I/O限制。具体来说,设置了每秒最大IOPS(IO操作每秒)为1000,并设置了每秒最大字节传输速率为10MB。

┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$virsh  blkdeviotune workstation  vda --total-iops-sec 1000 --total-bytes-sec 10MB┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$virsh dumpxml workstation | grep -A2 iotune<iotune><total_bytes_sec>10000000</total_bytes_sec><total_iops_sec>1000</total_iops_sec></iotune><alias name='virtio-disk0'/><address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$

虚拟化性能监控

查看设备 IO 信息

┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$virsh  domblkstat workstation vda --human
Device: vdanumber of read operations:      15012number of bytes read:           437122048number of write operations:     3193number of bytes written:        71808512number of flush operations:     903total duration of reads (ns):   854291749703total duration of writes (ns):  93692774619total duration of flushes (ns): 7848596731

查看网络设备信息

┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$virsh domiflist workstation
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet4      bridge     privbr0    virtio      52:54:00:00:fa:09

查看网络状态

┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$virsh domifstat workstation vnet4
vnet4 rx_bytes 600038
vnet4 rx_packets 10176
vnet4 rx_errs 0
vnet4 rx_drop 0
vnet4 tx_bytes 72045
vnet4 tx_packets 610
vnet4 tx_errs 0
vnet4 tx_drop 0

查看内存信息,单位为 KB

┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$virsh  dommemstat workstation
actual 2097152
swap_in 0
swap_out 0
major_fault 304
minor_fault 147927
unused 1669348
available 1873292
usable 1631560
last_update 1696474286
rss 1246776┌──[root@liruilongs.github.io]-[/var/lib/libvirt/images]
└─$

博文部分内容参考

© 文中涉及参考链接内容版权归原作者所有,如有侵权请告知,这是一个开源项目,如果你认可它,不要吝啬星星哦 😃


https://lonesysadmin.net/tag/linux-vm-performance-tuning/

《 Red Hat Performance Tuning 442 》


© 2018-2024 liruilonger@gmail.com, All rights reserved. 保持署名-非商用-相同方式共享(CC BY-NC-SA 4.0)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/671259.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

BLEUScore AttributeError: ‘list‘ object has no attribute ‘split‘——问题解决

目录 问题解决 问题 出现错误&#xff1a; BLEUScore AttributeError: ‘list’ object has no attribute ‘split’ 解决 应该是torchmetrics版本对torch的要求&#xff0c;需要对应版本: pip install torchmetrics0.6.2具体需要根据自己版本去降低&#xff0c;一般是往低…

Unet 实战分割项目、多尺度训练、多类别分割

1. 介绍 之前写了篇二值图像分割的项目&#xff0c;支持多尺度训练&#xff0c;网络采用backbone为vgg的unet网络。缺点就是没法实现多类别的分割&#xff0c;具体可以参考&#xff1a;二值图像分割统一项目 本章只对增加的代码进行介绍&#xff0c;其余的参考上述链接博文 本…

在本地运行大型语言模型 (LLM) 的六种方法(2024 年 1 月)

一、说明 &#xff08;开放&#xff09;本地大型语言模型&#xff08;LLM&#xff09;&#xff0c;特别是在 Meta 发布LLaMA和后Llama 2&#xff0c;变得越来越好&#xff0c;并且被越来越广泛地采用。 在本文中&#xff0c;我想演示在本地&#xff08;即在您的计算机上&#x…

DataX详解和架构介绍

系列文章目录 一、 DataX详解和架构介绍 二、 DataX源码分析 JobContainer 三、DataX源码分析 TaskGroupContainer 四、DataX源码分析 TaskExecutor 五、DataX源码分析 reader 六、DataX源码分析 writer 七、DataX源码分析 Channel 文章目录 系列文章目录DataX是什么&#xff…

【QT】VS-code报错:LNK2019: 无法解析的外部符号

目录 0.环境 1.问题简述 2.分析报错原因 3.解决方法 1&#xff09;set() 相关语句 2&#xff09;target_link_libraries() 相关语句 4.参考 0.环境 windows11 、 vs-code 、 qt 、 c、编译器为vs2019-x86_amd64 1.问题简述 项目编译release版本时会报错&#xff1a;报错…

页面单跳转换率统计案例分析

需求说明 页面单跳转化率 计算页面单跳转化率&#xff0c;什么是页面单跳转换率&#xff0c;比如一个用户在一次 Session 过程中访问的页面路径 3,5,7,9,10,21&#xff0c;那么页面 3 跳到页面 5 叫一次单跳&#xff0c;7-9 也叫一次单跳&#xff0c; 那么单跳转化率就是要统计…

c语言--指针的传值调用和传址调用

目录 一、前言二、传值调用。三、传址调用四、总结 一、前言 学习指针的目的是使用指针解决问题&#xff0c;那什么问题&#xff0c;非指针不可呢&#xff1f; 二、传值调用。 写个函数&#xff0c;交换两个整数的内容。 #include<stdio.h> void Swap1(int x, int y)…

在 Java 中处理整数上溢和下溢

本文介绍整数数据类型的上溢和下溢以及该问题的处理。 Java 中整数上溢和下溢概述 如果您使用整数值&#xff0c;则可能会遇到上溢或下溢错误。 当我们错误地声明变量时&#xff0c;就会发生这种情况&#xff0c;例如分配的值超出了声明的数据类型的范围。 众所周知&#xff…

LabVIEW双光子荧光显微成像系统开发

双光子显微成像是一种高级荧光显微技术&#xff0c;广泛用于生物学和医学研究&#xff0c;尤其是用于活体组织的深层成像。在双光子成像过程中&#xff0c;振镜&#xff08;Galvo镜&#xff09;扮演了非常关键的角色&#xff0c;它负责精确控制激光束在样本上的扫描路径。以下是…

读分布式稳定性建设指南文档

最近还是在做一些和稳定性建设相关的事情&#xff0c;找到一份《分布式稳定性建设指南》文档&#xff0c;摘抄了其中的重点&#xff0c;以便后续回顾方便&#xff0c;一直没上传好资源&#xff0c;我之后再试试&#xff0c;原文内容质量非常高。 大家可以先看一级目录即可&…

掌握Web服务器之王:Nginx 学习网站全攻略!

介绍&#xff1a;Nginx是一款高性能的Web服务器&#xff0c;同时也是一个反向代理、负载均衡和HTTP缓存服务器。具体介绍如下&#xff1a; 轻量级设计&#xff1a;Nginx的设计理念是轻量级&#xff0c;这意味着它在占用最少的系统资源的同时提供高效的服务。 高并发能力&#x…

go 内存二进制数据操作

go 内存二进制数据操作 go 内存二进制数据直接操作 以数字类型为例 int(linux/macos 为int32,windows 为int64). 如果不清楚可以使用unsafe.Sizeof函数来查看(函数出来的值*8就是int位数) 若不使用内存二进制数据操作&#xff0c;你需要在每次获取数字内容时调用binary.Big…

五、机器学习模型及其实现1

1_机器学习 1&#xff09;基础要求&#xff1a;所有的数据全部变为了特征&#xff0c;而不是eeg信号了 python基础已经实现了特征提取、特征选择&#xff08;可选&#xff09;进行了数据预处理.预处理指对数据进行清洗、转换等处理&#xff0c;使数据更适合机器学习的工具。S…

完全背包总结二

1.完全背包和0/1背包的区别&#xff1f; 完全背包的物体有无限个&#xff0c;可以多次放入 0/1背包的物体只有一个&#xff0c;只能放入一次 2.关于物品遍历顺序 在0/1背包中为了防止物品被重复放入&#xff0c;所以选择倒序遍历背包 而完全背包中&#xff0c;可以重复放入…

Datax3.0+DataX-Web部署分布式可视化ETL系统

一、DataX 简介 DataX 是阿里云 DataWorks 数据集成的开源版本&#xff0c;主要就是用于实现数据间的离线同步。DataX 致力于实现包括关系型数据库&#xff08;MySQL、Oracle 等&#xff09;、HDFS、Hive、ODPS、HBase、FTP 等各种异构数据源&#xff08;即不同的数据库&#x…

找单身狗(C语言)

题目叙述&#xff1a; 一个数组中只有两个数字是出现一次&#xff0c;其他所有数字都出现了两次。 编写一个函数找出这两个只出现一次的数字。 例如&#xff1a; 数组的元素是&#xff1a;1&#xff0c;2&#xff0c;3&#xff0c;4&#xff0c;5&#xff0c;1&#xff0c;…

从零开始手写mmo游戏从框架到爆炸(八)— byte数组传输

导航&#xff1a;从零开始手写mmo游戏从框架到爆炸&#xff08;零&#xff09;—— 导航-CSDN博客 Netty帧解码器 Netty中&#xff0c;提供了几个重要的可以直接使用的帧解码器。 LineBasedFrameDecoder 行分割帧解码器。适用场景&#xff1a;每个上层数据包&#xff0c;使…

Rust 初体验

Rust 初体验 安装 打开官网&#xff0c;下载 rustup-init.exe&#xff0c; 选择缺省模式&#xff08;1&#xff09;安装。 国内源设置 在 .Cargo 目录下新建 config 文件&#xff0c;添加如下内容&#xff1a; [source.crates-io] registry "https://github.com/rus…

spring-security SecurityContextHolder

翻译版本【spring-security 6.2.1】SecurityContextHolder SecurityContextHolder Spring Security身份验证模型的核心是SecurityContextHolder。它包含SecurityContext。 SecurityContextHolder是Spring Security存储身份验证详细信息的地方。Spring Security并不关心Secur…

【C语言】深入理解函数指针

函数指针是 C 语言中一个非常有用且强大的概念&#xff0c;它允许我们将函数作为参数传递给其他函数、在运行时动态选择要调用的函数以及实现回调函数等功能。在本篇博客中&#xff0c;我们将深入探讨函数指针的概念、用法以及其在实际编程中的应用。 目录 前言 什么是函数指…