免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4751 | 回复: 8
打印 上一主题 下一主题

求助:MySQL内存持续增加问题。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-11 17:17 |只看该作者 |倒序浏览
本帖最后由 yaya888 于 2012-06-11 17:36 编辑

有一台MySQL数据库服务器,SSD硬盘,24G内存。
MySQL version 5.1.48,INNODB引擎,程序使用DBCP连接池,每天约INSERT&DELETE各300万数据。
运行一段时间后,占用内存持续增加,只增不减,现在已经占用93%,担心哪一天会挂掉。

-------------------------------------------------------------------------
top - 17:51:44 up 276 days, 18:32,  1 user,  load average: 0.37, 0.17, 0.11
Tasks: 200 total,   1 running, 199 sleeping,   0 stopped,   0 zombie
Cpu(s):  3.1%us,  0.2%sy,  0.0%ni, 96.5%id,  0.0%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:  24660072k total, 24532700k used,   127372k free,   215000k buffers
Swap:  1959920k total,  1628040k used,   331880k free,   604976k cached
-------------------------------------------------------------------------

my.cnf具体配置参数如下:
  1. [client]
  2. #password        = [your_password]
  3. port                = 3306
  4. socket                = /var/lib/mysql/mysql.sock

  5. [mysqld]
  6. # generic configuration options
  7. port                = 3306
  8. socket                = /var/lib/mysql/mysql.sock
  9. back_log = 500

  10. max_connections = 300

  11. max_connect_errors = 100

  12. table_open_cache = 2048

  13. max_allowed_packet = 16M

  14. binlog_cache_size = 1M

  15. max_heap_table_size = 64M

  16. sort_buffer_size = 8M

  17. join_buffer_size = 8M

  18. thread_cache_size = 8

  19. thread_concurrency = 24

  20. query_cache_size = 0

  21. ft_min_word_len = 4

  22. default-storage-engine = MYISAM

  23. thread_stack = 192K

  24. transaction_isolation = REPEATABLE-READ

  25. tmp_table_size = 64M

  26. log-bin=/usr/local/mysql/data/mysql-bin

  27. binlog-ignore-db=mysql
  28. binlog-ignore-db=nagios
  29. expire_logs_days=1
  30. # binary logging format - mixed recommended
  31. binlog_format=mixed

  32. log_slave_updates

  33. slow_query_log

  34. long_query_time = 10
  35. server-id = 31



  36. key_buffer_size = 32M

  37. read_buffer_size = 2M

  38. read_rnd_buffer_size = 16M

  39. bulk_insert_buffer_size = 64M

  40. myisam_sort_buffer_size = 128M

  41. myisam_max_sort_file_size = 10G

  42. myisam_repair_threads = 1

  43. myisam_recover

  44. innodb_additional_mem_pool_size = 16M

  45. innodb_buffer_pool_size = 17G

  46. innodb_data_file_path = ibdata1:10M:autoextend

  47. innodb_file_per_table
  48. skip-name-resolve
  49. innodb_file_io_threads = 4

  50. innodb_thread_concurrency = 16

  51. sync-binlog=1
  52. innodb_flush_log_at_trx_commit = 1

  53. innodb_log_buffer_size = 8M

  54. innodb_log_file_size = 1G

  55. innodb_log_files_in_group = 3

  56. innodb_max_dirty_pages_pct = 90

  57. innodb_flush_method=O_DIRECT

  58. innodb_lock_wait_timeout = 120


  59. [mysqldump]
  60. quick

  61. max_allowed_packet = 16M

  62. [mysql]
  63. no-auto-rehash

  64. [myisamchk]
  65. key_buffer_size = 512M
  66. sort_buffer_size = 512M
  67. read_buffer = 8M
  68. write_buffer = 8M

  69. [mysqlhotcopy]
  70. interactive-timeout

  71. [mysqld_safe]
  72. open-files-limit = 81920
复制代码

论坛徽章:
9
每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00数据库技术版块每周发帖之星
日期:2016-03-07 16:30:25
2 [报告]
发表于 2012-06-11 19:58 |只看该作者
Memory的Usage 不说明问题。
关键是SWAP的使用率是不是很高。 目前也就用了1G的样子(不过还是有少量换出)。

楼主top看下MySQL的实际占用内存是多少。 目前这个配置在20G以内的占用属于正常情况。

PS: 是独立的数据库服务器么? 有其他占内存的应用不?

论坛徽章:
2
摩羯座
日期:2014-05-29 17:38:40数据库技术版块每日发帖之星
日期:2016-08-05 06:20:00
3 [报告]
发表于 2012-06-11 20:21 |只看该作者
本帖最后由 devilkin0312 于 2012-06-11 20:29 编辑

配置:
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 17G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_per_table
skip-name-resolve
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
sync-binlog=1
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 8M
innodb_log_file_size = 1G

个人建议:
   1.这应该核心的db 了,配置参数分类放还是随便放,交叉放,为了便于管理,有个规范好点。在innodb的配置中读到skip-name-resolve,,,
   2.正如楼主担心的内存问题,我的感觉这份配置文件就看着网上各种优化手册改的,后续也许有更多的问题你担心,因为对系统到底使用多少内存,没底。
   3.具体的参数:innodb_buffer_pool_size = 17G  既然都这么大了,innodb_additional_mem_pool_size 为何是16M?额外的缓存不重要?
      innodb_log_buffer_size = 8M  innodb_log_file_size = 1G  innodb的undo log 对性能的影响一定比想象中大。记得没错的话官方配置文件都有建议log buffer多大合适。
      。。。。

论坛徽章:
4
CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52戌狗
日期:2013-12-27 15:08:11
4 [报告]
发表于 2012-06-12 11:26 |只看该作者
不会挂的 还好 可以在检查下大数据表的情况,定期做好处理

论坛徽章:
0
5 [报告]
发表于 2012-06-12 12:02 |只看该作者
本帖最后由 yaya888 于 2012-06-12 12:13 编辑

回复 2# cenalulu
top查看MySQL实际占用内存93%
是独立的数据库服务器,没有其他应用。
采用master-slave结构,这台是master。
slave服务器采用性能一般的SATA硬盘。


   

论坛徽章:
0
6 [报告]
发表于 2012-06-12 12:27 |只看该作者
补充SHOW INNODB STATUS信息:
  1. =====================================
  2. 120612 13:22:50 INNODB MONITOR OUTPUT
  3. =====================================
  4. Per second averages calculated from the last 32 seconds
  5. ----------
  6. SEMAPHORES
  7. ----------
  8. OS WAIT ARRAY INFO: reservation count 54008112, signal count 50453824
  9. Mutex spin waits 0, rounds 10127967236, OS waits 12747231
  10. RW-shared spins 164912833, OS waits 15844113; RW-excl spins 1613239184, OS waits 21422102
  11. --------
  12. FILE I/O
  13. --------
  14. I/O thread 0 state: waiting for i/o request (insert buffer thread)
  15. I/O thread 1 state: waiting for i/o request (log thread)
  16. I/O thread 2 state: waiting for i/o request (read thread)
  17. I/O thread 3 state: waiting for i/o request (write thread)
  18. Pending normal aio reads: 0, aio writes: 0,
  19. ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
  20. Pending flushes (fsync) log: 0; buffer pool: 0
  21. 18328067 OS file reads, 209359193 OS file writes, 106585251 OS fsyncs
  22. 1.50 reads/s, 19456 avg bytes/read, 5.66 writes/s, 5.53 fsyncs/s
  23. -------------------------------------
  24. INSERT BUFFER AND ADAPTIVE HASH INDEX
  25. -------------------------------------
  26. Ibuf: size 1, free list len 1203, seg size 1205,
  27. 3370447 inserts, 3370447 merged recs, 371552 merges
  28. Hash table size 38249683, node heap has 128616 buffer(s)
  29. 8930.85 hash searches/s, 9807.01 non-hash searches/s
  30. ---
  31. LOG
  32. ---
  33. Log sequence number 481 1846483500
  34. Log flushed up to   481 1846483500
  35. Last checkpoint at  481 516827519
  36. 0 pending log writes, 0 pending chkp writes
  37. 86001520 log i/o's done, 4.91 log i/o's/second
  38. ----------------------
  39. BUFFER POOL AND MEMORY
  40. ----------------------
  41. Total memory allocated 21189269114; in additional pool allocated 16777216
  42. Dictionary memory allocated 5603384
  43. Buffer pool size   1179648
  44. Free buffers       0
  45. Database pages     1051032
  46. Modified db pages  194290
  47. Pending reads 0
  48. Pending writes: LRU 0, flush list 0, single page 0
  49. Pages read 44852084, created 33258919, written 314446357
  50. 1.78 reads/s, 17.25 creates/s, 24.00 writes/s
  51. Buffer pool hit rate 1000 / 1000
  52. --------------
  53. ROW OPERATIONS
  54. --------------
  55. 0 queries inside InnoDB, 0 queries in queue
  56. 12 read views open inside InnoDB
  57. Main thread process no. 11429, id 1190848832, state: sleeping
  58. Number of rows inserted 2712616480, updated 958817341, deleted 2650670338, read 1975317074980
  59. 712.04 inserts/s, 641.17 updates/s, 658.92 deletes/s, 6711.63 reads/s
复制代码

论坛徽章:
0
7 [报告]
发表于 2012-06-12 15:23 |只看该作者
回复 3# devilkin0312

补充SHOW INNODB STATUS信息,麻烦指点一下。
   

论坛徽章:
8
CU大牛徽章
日期:2013-09-18 15:20:48CU大牛徽章
日期:2013-09-18 15:20:58CU大牛徽章
日期:2013-09-18 15:21:06CU大牛徽章
日期:2013-09-18 15:21:12CU大牛徽章
日期:2013-09-18 15:21:17天秤座
日期:2013-10-30 14:01:03摩羯座
日期:2013-11-29 18:02:31luobin
日期:2016-06-17 17:46:36
8 [报告]
发表于 2012-06-13 17:58 |只看该作者
回复 7# yaya888

你的这个情况是比较正常的,一个是你数据量应该是接近18G或者大于18G,还有就是估计是某些大的查询或者存储过程涉及了非常多的记录,这种查询一多,内存占用就高。不过你不用太担心,因为你是ssd,就算写到swap问题也不大,系统也不会挂。
要优化的话,可以考虑优化一些返回数据量过大的sql,或者增加机器内存,内存条也不贵。


   

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
9 [报告]
发表于 2012-06-14 17:02 |只看该作者
linux下的内存使用原则,Lz还没有弄清楚

具体瓶颈在哪里,上面几个同学已经有提示
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP