磨砺技术珠矶,践行数据之道,追求卓越价值

回到上一级页面:PostgreSQL内部结构与源代码研究索引页    回到顶级页面:PostgreSQL索引页

[作者 高健@博客园  luckyjackgao@gmail.com]

可资参考的资料:

http://kaivanov.blogspot.com/2012/07/setting-up-linux-cgroups-control-groups.html

http://www.oracle.com/technetwork/articles/servers-storage-admin/resource-controllers-linux-1506602.html

首先用 hdparm测试磁盘读取的最大带宽:

hdparm --direct -t /dev/sda

测试结果为200MB/s以上。

然后给用户postgres设置参数,保持磁盘读写I/O为10MB/秒以下(此用户名下所有进程总和)。

# Configuration file generated by cgsnapshot
mount {
cpuset = /cgroup/cpuset;
cpu = /cgroup/cpu;
cpuacct = /cgroup/cpuacct;
memory = /cgroup/memory;
devices = /cgroup/devices;
freezer = /cgroup/freezer;
net_cls = /cgroup/net_cls;
blkio = /cgroup/blkio;
} group io-test {
perm {
task{
uid=postgres;
gid=postgres;
} admin{
uid=root;
gid=root;
} } blkio {
blkio.throttle.write_iops_device="";
blkio.throttle.read_iops_device="";
blkio.throttle.write_bps_device="8:0 10485760";
blkio.throttle.read_bps_device="8:0 10485760";
blkio.reset_stats="";
blkio.weight="";
blkio.weight_device="";
}
} [postgres@cent6 Desktop]$

再看

[postgres@cent6 Desktop]$ cat /etc/cgrules.conf
# /etc/cgrules.conf
#
#Each line describes a rule for a user in the forms:
#
#<user> <controllers> <destination>
#<user>:<process name> <controllers> <destination>
#
#Where:
# <user> can be:
# - an user name
# - a group name, with @group syntax
# - the wildcard *, for any user or group.
# - The %, which is equivalent to "ditto". This is useful for
# multiline rules where different cgroups need to be specified
# for various hierarchies for a single user.
#
# <process name> is optional and it can be:
# - a process name
# - a full command path of a process
#
# <controller> can be:
# - comma separated controller names (no spaces)
# - * (for all mounted controllers)
#
# <destination> can be:
# - path with-in the controller hierarchy (ex. pgrp1/gid1/uid1)
#
# Note:
# - It currently has rules based on uids, gids and process name.
#
# - Don't put overlapping rules. First rule which matches the criteria
# will be executed.
#
# - Multiline rules can be specified for specifying different cgroups
# for multiple hierarchies. In the example below, user "peter" has
# specified line rule. First line says put peter's task in test1/
# dir for "cpu" controller and second line says put peter's tasks in
# test2/ dir for memory controller. Make a note of "%" sign in second line.
# This is an indication that it is continuation of previous rule.
#
#
#<user> <controllers> <destination>
#
#john cpu usergroup/faculty/john/
#john:cp cpu usergroup/faculty/john/cp
#@student cpu,memory usergroup/student/
#peter cpu test1/
#% memory test2/
#@root * admingroup/
#* * default/
postgres blkio io-test/
# End of file
#
#
#
[postgres@cent6 Desktop]$

先用dd命令实际测试看看:

[postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile2 bs=4K count= oflag=direct
+ records in
+ records out
bytes (4.2 MB) copied, 0.372953 s, 11.2 MB/s
[postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile2 bs=8K count= oflag=direct
+ records in
+ records out
bytes (8.4 MB) copied, 0.733823 s, 11.4 MB/s
[postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile2 bs=8K count= oflag=direct
+ records in
+ records out
bytes (8.4 MB) copied, 0.733256 s, 11.4 MB/s
[postgres@cent6 Desktop]$
[postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile2 bs=16K count= oflag=direct
+ records in
+ records out
[postgres@cent6 Desktop]$

当然,如果dd执行时,开数据块太多,又是这种完全空的块,误差就会增大:

[postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile1 bs= count=
+ records in
+ records out
bytes (3.1 GB) copied, 57.6779 s, 53.3 MB/s
[postgres@cent6 Desktop]$

用实际的下载动作进行测试:

[postgres@cent6 Desktop]$ wget http://centos.arcticnetwork.ca/6.4/isos/x86_64/CentOS-6.4-x86_64-LiveCD.iso

再看看IO状态:

[postgres@cent6 Desktop]$ iostat -x
Linux 2.6.-.el6.x86_64 (cent6.gao) // _x86_64_ ( CPU) avg-cpu: %user %nice %system %iowait %steal %idle
1.38 0.00 3.55 12.16 0.00 82.91 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 7.50 1747.20 7.77 24.88 535.75 14224.09 452.17 12.54 384.25 4.41 14.40
dm- 0.00 0.00 13.79 1771.99 524.65 14224.07 8.26 1975.37 1106.16 0.09 16.73
dm- 0.00 0.00 0.38 0.00 3.03 0.00 8.00 0.00 3.68 2.34 0.09 avg-cpu: %user %nice %system %iowait %steal %idle
3.65 0.00 2.14 0.73 0.00 93.48 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 0.00 1.82 1.09 1.56 49.64 25.44 28.24 0.03 11.78 3.57 0.95
dm- 0.00 0.00 1.04 3.18 48.80 25.44 17.58 0.03 7.35 2.15 0.91
dm- 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 avg-cpu: %user %nice %system %iowait %steal %idle
1.65 0.00 1.65 0.98 0.00 95.72 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 0.00 60.28 0.00 1.44 0.00 492.12 341.14 0.02 11.79 8.86 1.28
dm- 0.00 0.00 0.00 61.51 0.00 492.12 8.00 0.59 9.54 0.21 1.28
dm- 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

除了一开始的峰值,util长期在2%-3%之间,基本达到效果。

[作者 高健@博客园  luckyjackgao@gmail.com]

磨砺技术珠矶,践行数据之道,追求卓越价值

回到上一级页面:PostgreSQL内部结构与源代码研究索引页    回到顶级页面:PostgreSQL索引页

使用cgroups来控制磁盘IO带宽的更多相关文章

  1. 【好书摘要】性能优化中CPU、内存、磁盘IO、网络性能的依赖

    系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试了,以后就可以一劳永逸了,也不是说书本上 ...

  2. Linux下java获取CPU、内存、磁盘IO、网络带宽使用率

    一.CPU 使用proc文件系统,"proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以文件系统的方式为访问系统内核数据的操作提供接口.用户和应用程序可以通过proc得 ...

  3. Linux按照CPU、内存、磁盘IO、网络性能监测

      系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试了,以后就可以一劳永逸了,也不是说书 ...

  4. inux按照CPU、内存、磁盘IO、网络性能监测

    http://my.oschina.net/chape/blog/159640 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长 ...

  5. linux性能优化cpu 磁盘IO MEM

    系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试了,以后就可以一劳永逸了,也不是说书本上 ...

  6. 网络IO和磁盘IO详解

    1. 缓存IO 缓存I/O又被称作标准I/O,大多数文件系统的默认I/O操作都是缓存I/O.在Linux的缓存I/O机制中,数据先从磁盘复制到内核空间的缓冲区,然后从内核空间缓冲区复制到应用程序的地址 ...

  7. linux 磁盘io监控

    我们在线上linux服务器排查问题时,一般会通过top.free.netstat.df -h等命令排查cpu.内存.网络和磁盘等问题.有的时候我们需要更进一步了解磁盘io的使用情况,那么本文就是重点讲 ...

  8. 性能优化中CPU、内存、磁盘IO、网络性能的依赖(转)

    关于系统性能优化,推荐一篇不错的博客! 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试 ...

  9. Linux按照CPU、内存、磁盘IO、网络性能监测【转载】

    本文转载地址:https://my.oschina.net/chape/blog/159640 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监 ...

随机推荐

  1. SAPGUI系统登录页面配置的SAProuter有什么用

    大家在安装完SAPGUI后,准备添加系统列表进行登录时,注意过这个SAProuter字段么? 从SAP的帮助文档上可以找到SAProuter的定义: https://help.sap.com/saph ...

  2. phoneGap的Android下编写phonegap 发送短信插件

    一.前端代码的编写 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  3. 对HandlerExecutionChain类的理解分析

    HandlerExecutionChain类比较简单,好理解. ==================================================================== ...

  4. thuwc2018 爆炸记

    从没考过这么差,必须好好总结一下.. $day1$: 上午到了雅礼洋湖,下午就开始考试.. 食堂饭菜还是很不错的,听说都是雅礼自己垫的? 下午的$day1$爆炸了.. 开考以后看了一下三个题,感觉一开 ...

  5. TensorFlow基础(二)实现神经网络

    (1)前向传播算法 神经网络的前向传播算法主要构成部分: 1.神经网络的输入: 2.神经网络的连接结构:神经网络是由神经元(节点)构成的 3.每个神经元中的参数. (2)TensorFlow随机数生成 ...

  6. vue中调用地图

    一. vue-amap,一个基于 Vue 2.x 和高德地图的地图组件 这个就不细说了,按照其文档,就能够安装下来. 二. 按照官方提供的方法引入 1.修改webpac.base.conf.js文件 ...

  7. 嵌入式 Linux 学习 之路

    1. 嵌入式 Linux  (首先百度了一下) 结果没有 看到 有信息的内容.2017年2月17日10:06:51 (嵌入式Linux 英文名:embedded Linux 简称 eLinux,Git ...

  8. 01-Python学习笔记-基础语法

    Python标识符 -d           在解析时显示调试信息 -O           生成优化代码 ( .pyo 文件 ) -S           启动时不引入查找Python路径的位置 - ...

  9. maven 环境变量 设置

    Maven安装与配置   一.需要准备的东西 1. JDK 2. Eclipse 3. Maven程序包 二.下载与安装 1. 前往https://maven.apache.org/download. ...

  10. iOS:绘图(18-01-25更)

    目录 1.UIBezierPath(贝塞尔曲线) 1).在重写 drawRect: 方法里使用 2).在普通方法里使用,需要画布. 3). 切圆角.指定位置圆角.任意形状. 4).彩色的动画加载圆圈. ...