OLTP

Tuned OLTP模板,针对常规业务数据库,优化延迟

Tuned OLTP模板主要针对延迟进行优化,此模板针对的机型是Dell R740 64核/400GB内存,使用PCI-E SSD的节点。您可以根据自己的实际机型进行调整。

  1. # tuned configuration
  2. #==============================================================#
  3. # File : tuned.conf
  4. # Mtime : 2020-06-29
  5. # Desc : Tune operatiing system to oltp mode
  6. # Path : /etc/tuned/oltp/tuned.conf
  7. # Author : Vonng(fengruohang@outlook.com)
  8. # Copyright (C) 2018-2021 Ruohang Feng
  9. #==============================================================#
  10. [main]
  11. summary=Optimize for PostgreSQL OLTP System
  12. include=network-latency
  13. [cpu]
  14. force_latency=1
  15. governor=performance
  16. energy_perf_bias=performance
  17. min_perf_pct=100
  18. [vm]
  19. # disable transparent hugepages
  20. transparent_hugepages=never
  21. [sysctl]
  22. #-------------------------------------------------------------#
  23. # KERNEL #
  24. #-------------------------------------------------------------#
  25. # disable numa balancing
  26. kernel.numa_balancing=0
  27. # total shmem size in bytes: $(expr $(getconf _PHYS_PAGES) / 2 \* $(getconf PAGE_SIZE))
  28. {% if param_shmall is defined and param_shmall != '' %}
  29. kernel.shmall = {{ param_shmall }}
  30. {% endif %}
  31. # total shmem size in pages: $(expr $(getconf _PHYS_PAGES) / 2)
  32. {% if param_shmmax is defined and param_shmmax != '' %}
  33. kernel.shmmax = {{ param_shmmax }}
  34. {% endif %}
  35. # total shmem segs 4096 -> 8192
  36. kernel.shmmni=8192
  37. # total msg queue number, set to mem size in MB
  38. kernel.msgmni=32768
  39. # max length of message queue
  40. kernel.msgmnb=65536
  41. # max size of message
  42. kernel.msgmax=65536
  43. kernel.pid_max=131072
  44. # max(Sem in Set)=2048, max(Sem)=max(Sem in Set) x max(SemSet) , max(Sem per Ops)=2048, max(SemSet)=65536
  45. kernel.sem=2048 134217728 2048 65536
  46. # do not sched postgres process in group
  47. kernel.sched_autogroup_enabled = 0
  48. # total time the scheduler will consider a migrated process cache hot and, thus, less likely to be remigrated
  49. # defaut = 0.5ms (500000ns), update to 5ms , depending on your typical query (e.g < 1ms)
  50. kernel.sched_migration_cost_ns=5000000
  51. #-------------------------------------------------------------#
  52. # VM #
  53. #-------------------------------------------------------------#
  54. # try not using swap
  55. vm.swappiness=0
  56. # disable when most mem are for file cache
  57. vm.zone_reclaim_mode=0
  58. # overcommit threshhold = 80%
  59. vm.overcommit_memory=2
  60. vm.overcommit_ratio=80
  61. # vm.dirty_background_bytes=67108864 # 64MB mem (2xRAID cache) wake the bgwriter
  62. vm.dirty_background_ratio=3 # latency-performance default
  63. vm.dirty_ratio=10 # latency-performance default
  64. # deny access on 0x00000 - 0x10000
  65. vm.mmap_min_addr=65536
  66. #-------------------------------------------------------------#
  67. # Filesystem #
  68. #-------------------------------------------------------------#
  69. # max open files: 382589 -> 167772160
  70. fs.file-max=167772160
  71. # max concurrent unfinished async io, should be larger than 1M. 65536->1M
  72. fs.aio-max-nr=1048576
  73. #-------------------------------------------------------------#
  74. # Network #
  75. #-------------------------------------------------------------#
  76. # max connection in listen queue (triggers retrans if full)
  77. net.core.somaxconn=65535
  78. net.core.netdev_max_backlog=8192
  79. # tcp receive/transmit buffer default = 256KiB
  80. net.core.rmem_default=262144
  81. net.core.wmem_default=262144
  82. # receive/transmit buffer limit = 4MiB
  83. net.core.rmem_max=4194304
  84. net.core.wmem_max=4194304
  85. # ip options
  86. net.ipv4.ip_forward=1
  87. net.ipv4.ip_nonlocal_bind=1
  88. net.ipv4.ip_local_port_range=32768 65000
  89. # tcp options
  90. net.ipv4.tcp_timestamps=1
  91. net.ipv4.tcp_tw_reuse=1
  92. net.ipv4.tcp_tw_recycle=0
  93. net.ipv4.tcp_syncookies=0
  94. net.ipv4.tcp_synack_retries=1
  95. net.ipv4.tcp_syn_retries=1
  96. # tcp read/write buffer
  97. net.ipv4.tcp_rmem="4096 87380 16777216"
  98. net.ipv4.tcp_wmem="4096 16384 16777216"
  99. net.ipv4.udp_mem="3145728 4194304 16777216"
  100. # tcp probe fail interval: 75s -> 20s
  101. net.ipv4.tcp_keepalive_intvl=20
  102. # tcp break after 3 * 20s = 1m
  103. net.ipv4.tcp_keepalive_probes=3
  104. # probe peroid = 1 min
  105. net.ipv4.tcp_keepalive_time=60
  106. net.ipv4.tcp_fin_timeout=5
  107. net.ipv4.tcp_max_tw_buckets=262144
  108. net.ipv4.tcp_max_syn_backlog=8192
  109. net.ipv4.neigh.default.gc_thresh1=80000
  110. net.ipv4.neigh.default.gc_thresh2=90000
  111. net.ipv4.neigh.default.gc_thresh3=100000
  112. net.bridge.bridge-nf-call-iptables=1
  113. net.bridge.bridge-nf-call-ip6tables=1
  114. net.bridge.bridge-nf-call-arptables=1
  115. # max connection tracking number
  116. net.netfilter.nf_conntrack_max=1048576

最后修改 2022-05-27: init commit (1e3e284)