zoukankan      html  css  js  c++  java
  • NUMA架构的优缺点

     

    numa把一台计算机分成多个节点(node),每个节点内部拥有多个CPU,节点内部使用共有的内存控制器,节点之间是通过互联模块进行连接和信息交互。
    因此节点的所有内存对于本节点所有的CPU都是等同的,对于其他节点中的所有CPU都不同。因此每个CPU可以访问整个系统内存,但是访问本地节点的内存速度
    最快(不经过互联模块),访问非本地节点的内存速度较慢(需要经过互联模块),即CPU访问内存的速度与节点的距离有关,该距离成为Node Distance。
    查看当前numa的节点情况:
    numactl --hardware

    节点之间的距离(Node Distance)指从节点1上访问节点0上的内存需要付出的代价的一种表现形式。
    Numa内存分配策略有一下四种:
    缺省default:总是在本地节点分配(当前进程运行的节点上)。
    绑定bind:强制分配到指定节点上。
    交叉interleavel:在所有节点或者指定节点上交叉分配内存。
    优先preferred:在指定节点上分配,失败则在其他节点上分配。
    查看当前系统numa策略:
    numactl --show
    因为numa默认的内存分配策略是优先在进程所在CPU的本地内存中分配,会导致CPU节点之间内存分配不均衡,
    当某个CPU节点内存不足时,会导致swap产生,而不是从远程节点分配内存,这就是swap insanity现象。
    MySQL服务器为什么需要关闭numa?
    MySQL是单进程多线程架构数据库,当numa采用默认内存分配策略时,MySQL进程会被并且仅仅会被分配到numa的一个节点上去。
    假设这个节点的本地内存为10GB,而MySQL配置20GB内存,超出节点本地内存部分(20GB-10GB)Linux会使用swap而不是使用其他节点的物理内存。
    在这种情况下,能观察到虽然系统总的可用内存还未用完,但是MySQL进程已经开始在使用swap了。
    如果单机只运行一个MySQL实例,可以选择关闭numa,关闭nuam有两种方法:
    1.硬件层,在BIOS中设置关闭;
    2.OS内核,启动时设置numa=off。
    修改/etc/grub.conf文件,在kernel那行追加numa=off;
    [root@node130 ~]#  vim /boot/grub/grub.conf
    title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
            root (hd0,0)
            kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=cb7d8bdc-28a5-4dbd-b04a-3ad9ee3e6bba rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet numa=off
    保存后重启服务器,再次检查numa只剩下一个节点就成功了:
    [root@node130 ~]# numactl --hardware
    available: 1 nodes (0)
    node 0 cpus: 0
    node 0 size: 2047 MB
    node 0 free: 1514 MB
    node distances:
    node   0 
      0:  10

    IO调度
    在不同场景下选择不同的IO调度器:
    在完全随机访问环境下,由于CFQ可能会造成小IO的相应延时增加,所以应设置为deadline,这样更稳定。
    对于SSD设备,采用NOOP或者deadline也可以获取比默认调度器更好的性能。
    查看当前系统支持的IO调度算法:
    [root@node130 Desktop]# dmesg|grep -i scheduler
    io scheduler noop registered
    io scheduler anticipatory registered
    io scheduler deadline registered
    io scheduler cfq registered (default)
    查看当前设备(/dev/sda)使用的IO调度算法:
    [root@node130 Desktop]# cat /sys/block/sda/queue/scheduler 
    noop anticipatory deadline [cfq] 

    修当前块设备(/dev/sda)使用的IO调度算法,修改IO调度算法后直接生效:
    echo "deadline">> /sys/block/sda/queue/scheduler

    永久修改IO调度算法,可以通过修改内核引导参数,增加elevator=调度算法:
    vim /boot/grub/menu.lst
    kernel /boot/                                root=LABEL=/ elevator=deadline

    [root@node130 Desktop]# vim /etc/grub.conf

    title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
            root (hd0,0)
            kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=28d9f713-f49d-49ae-9e63-401986d11ab2 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet numa=off elevator=deadline

    交换分区

    swappiness是Linux的一个内核参数,用户控制Linux物理内存进行swap页交换的相对权重,尽量减少系统的页缓存被从内存中清除的情况。取值范围是0~100,vm.swappiness的值越低,Linux内核会尽量不进行swap交换页的操作,vm.swappiness的值越高,Linux会越多的使用swap空间。Linux系统默认值是60,当系统需要内存时,有60%的概率使用swap。对于大多数桌面系统,设置为100可以提高系统的整体性能;对于数据库应用服务器,设置为0,可以提高物理内存的使用率,进而提高数据库服务的响应性能。

    [root@node130 ~]# vim /etc/sysctl.conf 
    vm.swappiness=0

    sysctl -p 生效
    [root@node130 ~]# sysctl -a|grep swap
    vm.swappiness = 0

     

    NUMA特性禁用

     
    一、检查OS是否开启NUMA
    # numactl --hardware
    二、Linux OS层面禁用NUMA
    1、修改 grub.conf
    # vi /boot/grub/grub.conf
    #/* Copyright 2010, Oracle. All rights reserved. */
     
    default=0
    timeout=5
    hiddenmenu
    foreground=000000
    background=ffffff
    splashimage=(hd0,0)/boot/grub/oracle.xpm.gz
     
    title Trying_C0D0_as_HD0
    root (hd0,0)
    kernel /boot/vmlinuz-2.6.18-128.1.16.0.1.el5 root=LABEL=DBSYS ro bootarea=dbsys rhgb quiet console=ttyS0,115200n8 console=tty1 crashkernel=128M@16M numa=off
    initrd /boot/initrd-2.6.18-128.1.16.0.1.el5.img
     
    2、重启Linux操作系统
    # /sbin/reboot
     
    3、确认OS层面禁用NUMA是否成功
    # cat /proc/cmdline
    root=LABEL=DBSYS ro bootarea=dbsys rhgb quiet console=ttyS0,115200n8 console=tty1 crashkernel=128M@16M numa=off
    # numactl --hardware
     
    三、SuSE Linux禁用NUMA示例
    对于suse系统来说,只要不重新编译内核,系统默认是启用numa功能的(可以通过/boot/config-`uname -r`查看)。
    尝试在/boot/grub/menu.lst文件中kernel一行的选项中添加 numa=off 参数禁止numa功能,重启系统生效。
    # more /boot/grub/menu.lst
    # Modified by YaST2. Last modification on Mon Dec 23 23:19:15 CST 2013
    default 0
    timeout 8
    ##YaST - generic_mbr
    gfxmenu (hd0,7)/message
    ##YaST - activate
     
    ###Don't change this comment - YaST2 identifier: Original name: linux###
    title SUSE Linux Enterprise Server 11 SP1 - 2.6.32.59-0.7
      root (hd0,7)
      kernel /vmlinuz-2.6.32.59-0.7-default root=/dev/disk/by-id/scsi-3600605b005a36fc0190ea623797d7bba-part2 resume=/dev/disk/by-id/scsi-3600605b005a36fc0190ea623797d7bba-part1 splash=silent crashkernel=256M-:128M showopts vga=0x31a elevator=deadline numa=off
      initrd /initrd-2.6.32.59-0.7-default
     
    ###Don't change this comment - YaST2 identifier: Original name: failsafe###
    title Failsafe -- SUSE Linux Enterprise Server 11 SP1 - 2.6.32.59-0.7
      root (hd0,7)
      kernel /vmlinuz-2.6.32.59-0.7-default root=/dev/disk/by-id/scsi-3600605b005a36fc0190ea623797d7bba-part2 showopts ide=nodma apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 nomodeset x11failsafe vga=0x31a
      initrd /initrd-2.6.32.59-0.7-default
     
    ###Don't change this comment - YaST2 identifier: Original name: linux###
    title SUSE Linux Enterprise Server 11 SP1 - 2.6.32.12-0.7
      root (hd0,7)
      kernel /vmlinuz-2.6.32.12-0.7-default root=/dev/disk/by-id/scsi-3600605b005a36fc0190ea623797d7bba-part2 resume=/dev/disk/by-id/scsi-3600605b005a36fc0190ea623797d7bba-part1 splash=silent crashkernel=256M-:128M showopts vga=0x31a
      initrd /initrd-2.6.32.12-0.7-default
     
    ###Don't change this comment - YaST2 identifier: Original name: failsafe###
    title Failsafe -- SUSE Linux Enterprise Server 11 SP1 - 2.6.32.12-0.7
      root (hd0,7)
      kernel /vmlinuz-2.6.32.12-0.7-default root=/dev/disk/by-id/scsi-3600605b005a36fc0190ea623797d7bba-part2 showopts ide=nodma apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 nomodeset x11failsafe vga=0x31a
      initrd /initrd-2.6.32.12-0.7-default
     
     
    # numactl --hardware
    available: 1 nodes (0)
    node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    node 0 size: 65519 MB
    node 0 free: 61097 MB
    No distance information available.
    BMSuiteDB1:~ # cat /proc/cmdline
    root=/dev/disk/by-id/scsi-3600605b005a36fc0190ea623797d7bba-part2 resume=/dev/disk/by-id/scsi-3600605b005a36fc0190ea623797d7bba-part1 splash=silent crashkernel=256M-:128M vga=0x31a elevator=deadline numa=off
     
  • 相关阅读:
    poj 3666 Making the Grade
    poj 3186 Treats for the Cows (区间dp)
    hdu 1074 Doing Homework(状压)
    CodeForces 489C Given Length and Sum of Digits...
    CodeForces 163A Substring and Subsequence
    CodeForces 366C Dima and Salad
    CodeForces 180C Letter
    CodeForces
    hdu 2859 Phalanx
    socket接收大数据流
  • 原文地址:https://www.cnblogs.com/pipci/p/12241431.html
Copyright © 2011-2022 走看看