使用MySQL和Redis处理大数据

时间:2013-05-22 15:17:26

标签: php mysql apache redis centos

我需要数据库大师的帮助。

在MySQL中导出为SQL文件时,我有一个超过1.5 GB的大数据库。

我现在面临的问题是,对包含数百万数据的统计信息等表的查询只会导致服务器崩溃。

我现在想到的解决方案很少,我倾向于Redis实现大型表只有Redis和MySQL一起工作。我认为我应该保留MySQL,因为它设置了很多复杂的关系,特别是在定义权限和访问控制列表时。此外,我不确定Redis是否可以安全地存储付款等敏感数据。

这是解决问题的最佳方法吗?

我听说是MySQL分片,我听说它对性能提升非常有效。

在这种情况下你会做什么?

UPDATE - 这是我从MySQLTuner获得的:

-------- Performance Metrics -------------------------------------------------
[--] Up for: 9d 1h 9m 33s (98M q [126.517 qps], 2M conn, TX: 354B, RX: 15B)
[--] Reads / Writes: 82% / 18%
[--] Total buffers: 232.0M global + 2.8M per thread (151 max threads)
[OK] Maximum possible memory usage: 647.2M (10% of installed RAM)
[OK] Slow queries: 0% (876/98M)
[!!] Highest connection usage: 100%  (152/151)
[OK] Key buffer size / total MyISAM indexes: 8.0M/294.2M
[OK] Key buffer hit rate: 100.0% (148B cached / 2M reads)
[OK] Query cache efficiency: 81.0% (64M cached / 79M selects)
[!!] Query cache prunes per day: 36845
[OK] Sorts requiring temporary tables: 0% (27 temp sorts / 7M sorts)
[!!] Joins performed without indexes: 8358004
[!!] Temporary tables created on disk: 44% (8M on disk / 18M total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (400 open / 266K opened)
[OK] Open file limit used: 38% (398/1K)
[OK] Table locks acquired immediately: 99% (42M immediate / 42M locks)
[OK] InnoDB data size / buffer pool: 67.8M/128.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Enable the slow query log to troubleshoot bad queries
    Reduce or eliminate persistent connections to reduce connection usage
    Adjust your join queries to always utilize indexes
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries without LIMIT clauses
    Set thread_cache_size to 4 as a starting value
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    max_connections (> 151)
    wait_timeout (< 28800)
    interactive_timeout (< 28800)
    query_cache_size (> 64M)
    join_buffer_size (> 128.0K, or always use indexes with joins)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    thread_cache_size (start at 4)
    table_cache (> 400)

2 个答案:

答案 0 :(得分:2)

没有通用限制,但1.5GB甚至不应被视为大数据。您没有提供TPS(每秒事务数)的数量,这可能表示您的工作量。

但是,切换到非关系型解决方案会导致比尝试优化RDBMS更多的问题。所以,你应该问问自己:

  • 哪些查询粉碎了服务器?
  • 您的查询是否使用了良好的索引?
  • 长时间运行的查询会锁定表吗?
  • 您的服务器配置良好吗?你有没有设置innodb_buffer_pool_size来使用80%的可用内存? 看看Percona的这些幻灯片:http://www.percona.com/files/presentations/WEBINAR2012-03-Optimizing-MySQL-Configuration.pdf
  • 您使用的是使系统变慢的东西吗?例如,只要您需要良好的性能,SELinux就会很糟糕。

如果所有答案都是“是”,那么请考虑使用其他解决方案:

  • 升级硬件(按此重要性顺序:更多内存,更快的磁盘,更快的总线CPU)
  • MySQL分区
  • 来自Percona的XtraDB集群
  • Shard Query存储引擎,它进行一些分片和负载平衡

答案 1 :(得分:0)

1.5千兆的数据不是大数据,如果配置正确,MySql可以正常处理它。

因此,在您查看其他任何内容之前,您的MySql数据库确保您已尝试并排除此列表中的所有内容:

  • 你调整了你的mysql配置(默认很糟糕)
  • 您正在使用索引
  • 您优化了查询(确保实际使用索引)
  • 你使用尽可能多的ram

在此列表的末尾,您将了解更多有关MySql的信息,并且您可能不需要在堆栈中添加额外的组件。 (或者您可以聘请DBA并获得相同的结果)

相关问题