每当我找到成功的钥匙,就发现有人把锁芯给换了。
背景
操作系统为了适应更多的硬件环境,许多初始的设置值,宽容度都很高。
如果不经调整,这些值可能无法适应HPC,或者硬件稍好些的环境。
无法发挥更好的硬件性能,甚至可能影响某些应用软件的使用,特别是数据库。
数据库关心的OS内核参数
512GB 内存为例
1.
参数
1 | fs.aio-max-nr |
fs.nr_open
1 |
|
CentOS 6, 7
1 |
|
nr_open:
This denotes the maximum number of file-handles a process can
allocate. Default value is 1024*1024 (1048576) which should be
enough for most machines. Actual limit depends on RLIMIT_NOFILE
resource limit.
它还影响security/limits.conf 的文件句柄限制,单个进程的打开句柄不能大于fs.nr_open,所以要加大文件句柄限制,首先要加大nr_open
推荐设置
对于有很多对象(表、视图、索引、序列、物化视图等)的PostgreSQL数据库,建议设置为2000万,
例如fs.nr_open=20480000
## 数据库关心的资源限制
1\. 通过/etc/security/limits.conf设置,或者ulimit设置
2\. 通过/proc/$pid/limits查看当前进程的设置
- core - limits the core file size (KB)
- memlock - max locked-in-memory address space (KB)
- nofile - max number of open files 建议设置为1000万 , 但是必须设置sysctl, fs.nr_open大于它,否则会导致系统无法登陆。
- nproc - max number of processes
以上四个是非常关心的配置
….
- data - max data size (KB)
- fsize - maximum filesize (KB)
- rss - max resident set size (KB)
- stack - max stack size (KB)
- cpu - max CPU time (MIN)
- as - address space limit (KB)
- maxlogins - max number of logins for this user
- maxsyslogins - max number of logins on the system
- priority - the priority to run user process with
- locks - max number of file locks the user can hold
- sigpending - max number of pending signals
- msgqueue - max memory used by POSIX message queues (bytes)
- nice - max nice priority allowed to raise to values: [-20, 19]
- rtprio - max realtime priority
## 数据库关心的IO调度规则
1\. 目前操作系统支持的IO调度策略包括cfq, deadline, noop 等。
/kernel-doc-xxx/Documentation/block
-r–r–r– 1 root root 674 Apr 8 16:33 00-INDEX
-r–r–r– 1 root root 55006 Apr 8 16:33 biodoc.txt
-r–r–r– 1 root root 618 Apr 8 16:33 capability.txt
-r–r–r– 1 root root 12791 Apr 8 16:33 cfq-iosched.txt
-r–r–r– 1 root root 13815 Apr 8 16:33 data-integrity.txt
-r–r–r– 1 root root 2841 Apr 8 16:33 deadline-iosched.txt
-r–r–r– 1 root root 4713 Apr 8 16:33 ioprio.txt
-r–r–r– 1 root root 2535 Apr 8 16:33 null_blk.txt
-r–r–r– 1 root root 4896 Apr 8 16:33 queue-sysfs.txt
-r–r–r– 1 root root 2075 Apr 8 16:33 request.txt
-r–r–r– 1 root root 3272 Apr 8 16:33 stat.txt
-r–r–r– 1 root root 1414 Apr 8 16:33 switching-sched.txt
-r–r–r– 1 root root 3916 Apr 8 16:33 writeback_cache_control.txt
如果你要详细了解这些调度策略的规则,可以查看WIKI或者看内核文档。
从这里可以看到它的调度策略
cat /sys/block/vdb/queue/scheduler
noop [deadline] cfq
修改
echo deadline > /sys/block/hda/queue/scheduler
或者修改启动参数
grub.conf
elevator=deadline`
从很多测试结果来看,数据库使用deadline调度,性能会更稳定一些。
其他
1. 关闭透明大页
2. 禁用NUMA
3. SSD的对齐