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

回到上一级页面: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测试磁盘读取的最大带宽:

  1. hdparm --direct -t /dev/sda

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

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

  1. # Configuration file generated by cgsnapshot
  2. mount {
  3. cpuset = /cgroup/cpuset;
  4. cpu = /cgroup/cpu;
  5. cpuacct = /cgroup/cpuacct;
  6. memory = /cgroup/memory;
  7. devices = /cgroup/devices;
  8. freezer = /cgroup/freezer;
  9. net_cls = /cgroup/net_cls;
  10. blkio = /cgroup/blkio;
  11. }
  12.  
  13. group io-test {
  14. perm {
  15. task{
  16. uid=postgres;
  17. gid=postgres;
  18. }
  19.  
  20. admin{
  21. uid=root;
  22. gid=root;
  23. }
  24.  
  25. } blkio {
  26. blkio.throttle.write_iops_device="";
  27. blkio.throttle.read_iops_device="";
  28. blkio.throttle.write_bps_device="8:0 10485760";
  29. blkio.throttle.read_bps_device="8:0 10485760";
  30. blkio.reset_stats="";
  31. blkio.weight="";
  32. blkio.weight_device="";
  33. }
  34. }
  35.  
  36. [postgres@cent6 Desktop]$

再看

  1. [postgres@cent6 Desktop]$ cat /etc/cgrules.conf
  2. # /etc/cgrules.conf
  3. #
  4. #Each line describes a rule for a user in the forms:
  5. #
  6. #<user> <controllers> <destination>
  7. #<user>:<process name> <controllers> <destination>
  8. #
  9. #Where:
  10. # <user> can be:
  11. # - an user name
  12. # - a group name, with @group syntax
  13. # - the wildcard *, for any user or group.
  14. # - The %, which is equivalent to "ditto". This is useful for
  15. # multiline rules where different cgroups need to be specified
  16. # for various hierarchies for a single user.
  17. #
  18. # <process name> is optional and it can be:
  19. # - a process name
  20. # - a full command path of a process
  21. #
  22. # <controller> can be:
  23. # - comma separated controller names (no spaces)
  24. # - * (for all mounted controllers)
  25. #
  26. # <destination> can be:
  27. # - path with-in the controller hierarchy (ex. pgrp1/gid1/uid1)
  28. #
  29. # Note:
  30. # - It currently has rules based on uids, gids and process name.
  31. #
  32. # - Don't put overlapping rules. First rule which matches the criteria
  33. # will be executed.
  34. #
  35. # - Multiline rules can be specified for specifying different cgroups
  36. # for multiple hierarchies. In the example below, user "peter" has
  37. # specified line rule. First line says put peter's task in test1/
  38. # dir for "cpu" controller and second line says put peter's tasks in
  39. # test2/ dir for memory controller. Make a note of "%" sign in second line.
  40. # This is an indication that it is continuation of previous rule.
  41. #
  42. #
  43. #<user> <controllers> <destination>
  44. #
  45. #john cpu usergroup/faculty/john/
  46. #john:cp cpu usergroup/faculty/john/cp
  47. #@student cpu,memory usergroup/student/
  48. #peter cpu test1/
  49. #% memory test2/
  50. #@root * admingroup/
  51. #* * default/
  52. postgres blkio io-test/
  53. # End of file
  54. #
  55. #
  56. #
  57. [postgres@cent6 Desktop]$

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

  1. [postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile2 bs=4K count= oflag=direct
  2. + records in
  3. + records out
  4. bytes (4.2 MB) copied, 0.372953 s, 11.2 MB/s
  5. [postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile2 bs=8K count= oflag=direct
  6. + records in
  7. + records out
  8. bytes (8.4 MB) copied, 0.733823 s, 11.4 MB/s
  9. [postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile2 bs=8K count= oflag=direct
  10. + records in
  11. + records out
  12. bytes (8.4 MB) copied, 0.733256 s, 11.4 MB/s
  13. [postgres@cent6 Desktop]$
  14. [postgres@cent6 Desktop]$ dd if=/dev/zero of=testfile2 bs=16K count= oflag=direct
  15. + records in
  16. + records out
  17. [postgres@cent6 Desktop]$

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

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

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

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

再看看IO状态:

  1. [postgres@cent6 Desktop]$ iostat -x
  2. Linux 2.6.-.el6.x86_64 (cent6.gao) // _x86_64_ ( CPU)
  3.  
  4. avg-cpu: %user %nice %system %iowait %steal %idle
  5. 1.38 0.00 3.55 12.16 0.00 82.91
  6.  
  7. Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
  8. sda 7.50 1747.20 7.77 24.88 535.75 14224.09 452.17 12.54 384.25 4.41 14.40
  9. dm- 0.00 0.00 13.79 1771.99 524.65 14224.07 8.26 1975.37 1106.16 0.09 16.73
  10. dm- 0.00 0.00 0.38 0.00 3.03 0.00 8.00 0.00 3.68 2.34 0.09
  11.  
  12. avg-cpu: %user %nice %system %iowait %steal %idle
  13. 3.65 0.00 2.14 0.73 0.00 93.48
  14.  
  15. Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
  16. sda 0.00 1.82 1.09 1.56 49.64 25.44 28.24 0.03 11.78 3.57 0.95
  17. dm- 0.00 0.00 1.04 3.18 48.80 25.44 17.58 0.03 7.35 2.15 0.91
  18. dm- 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  19.  
  20. avg-cpu: %user %nice %system %iowait %steal %idle
  21. 1.65 0.00 1.65 0.98 0.00 95.72
  22.  
  23. Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
  24. sda 0.00 60.28 0.00 1.44 0.00 492.12 341.14 0.02 11.79 8.86 1.28
  25. dm- 0.00 0.00 0.00 61.51 0.00 492.12 8.00 0.59 9.54 0.21 1.28
  26. 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. php生成csv文件并提供下载及相关注意事项

    1.生成文件过程略,只要逗号分割就可以了 2.提供下载加上如下代码: header("Content-type: application/octet-stream"); heade ...

  2. 洛谷 P4593 【[TJOI2018]教科书般的亵渎】

    题目分析 一眼看上去就像是一个模拟题目,但是\(n\)的范围过大. 冷静分析一下发现难点在于如何快速求出幂和. 考虑使用伯努利数. \(B_0=1\) \(B_n=-\frac{1}{n+1}\sum ...

  3. SQL Server的跨服务器数据访问方法

    想要在SQL服务器上访问另一个服务器的数据,可以采用此方式: 1.建立数据库链接: 右键“链接服务器”,选择“新建链接服务器...” 以上的操作也可以通过SQL脚本实现: exec sp_addlin ...

  4. UVA10820 Send a Table

    嘟嘟嘟 [欧拉函数] 大致题意:如果知道f(a, b),就可以求出f(a * k, b * k).现给出一个n,求至少需要知道几个二元组(a, b),使所有的f(x, y)都能求出来.(1 <= ...

  5. [HNOI2007]紧急疏散EVACUATE

    嘟嘟嘟 看数据范围,第一反应觉得爆搜是不是能骗点分,但发现爆搜太难写了,于是就开始想想正解…… 正解大概猜到了是网络流,但是怎么把时间这个条件加入到图的内容中,却困扰了我好半天,总是感觉把这种不同维度 ...

  6. 2springboot:快速创建springboot项目

    使用IDEA快速创建springboot项目流程: 创建新的项目选择 项目的命名以及包名 需要什么包就导入什么包 进行测试的单元 <dependency> <groupId>o ...

  7. springmvc错误集锦-dubbo包含低版本的spring包,依赖的时候应该排除Caused by: java.lang.reflect.MalformedParameterizedTypeException

    dubbo 常见错误 1. Caused by: java.lang.reflect.MalformedParameterizedTypeException 启动时报错,原因是dubbo 依赖 spr ...

  8. HTML5前端性能优化——浏览器兼容与前端性能优化

    一.浏览器兼容 1.1.概要 世界上没有任何一个浏览器是一样的,同样的代码在不一样的浏览器上运行就存在兼容性问题.不同浏览器其内核亦不尽相同,相同内核的版本不同,相同版本的内核浏览器品牌不一样,各种运 ...

  9. easy-im:一款基于netty的即时通讯系统

    介绍 easy-im是面向开发者的一款轻量级.开箱即用的即时通讯系统,帮助开发者快速搭建消息推送等功能. 基于easy-im,你可以快速实现以下功能: + 聊天软件 + IoT消息推送 基本用法 项目 ...

  10. Oracle中case的第二种用法

    procedure P_GetProVerSingInfo_2018(varFileID in varchar2, p_cr1 out refcontent, p_cr2 out refcontent ...