补充一些有关mysql复制方面的资料
上一篇 / 下一篇 2008-10-22 16:01:53 / 个人分类:LAMP
有兴趣的可以参考:
【replication】
Thoughts
on MySQL Replication
http://www.mysqlperformanceblog.com/2006/07/07/thoughts-on-mysql-replication/
Figuring
out what limits MySQL Replication
http://www.mysqlperformanceblog.com/2007/03/07/figuring-out-what-limits-mysql-replication/
MySQL
Replication and Slow Queries
http://www.mysqlperformanceblog.com/2007/03/28/mysql-replication-and-slow-queries/
Replication
will live!
http://dammit.lt/2008/04/12/replication-will-live/
Managing
Slave Lag with MySQL Replication
http://www.mysqlperformanceblog.com/2007/10/12/managing-slave-lag-with-mysql-replication/
OReIlly.High.Performance.MySQL.Second.Edition.Jun.2008.eBook-DDU.rar
P367
MySQL
Slave Delay Explained And 7 Ways To Battle It
http://beerpla.net/2008/09/05/mysql-slave-delay-explained-and-7-ways-to-battle-it/
Fighting
MySQL Replication Lag
http://www.mysqlperformanceblog.com/2008/09/22/fighting-mysql-replication-lag/
Three
ways to know when a MySQL slave is about to start lagging
http://www.mysqlperformanceblog.com/2008/10/08/three-ways-to-know-when-a-mysql-slave-is-about-to-start-lagging/
数据库主从同步的延迟虽然看上去跟系统运维的关系更加密切,但对开发人员来说,了解如何避免或减少延迟,可以使得在设计之初就去考虑这类问题,最终解决方案也会更好
源:MySQL
Performance Blog木铎校园 BBS 社区4C"d:HK9bL OMW8s
投递时间:2008年9月23日12:17木铎校园 BBS 社区4z@5[+].g}t E'DXd
作者:peter
T/@4Z3uDk0主题:Fighting MySQL Replication
Lag
z{/}7h1`0The problem of
MySQL Replication unable to catch up is quite common in MySQL world and in fact
Ialready
wroteabout it. There are many aspects of managing mysql replication lag
such as using proper hardware and configuring it properly. In this post I will
just look at couple of query design mistakes which result in low hanging fruit
troubleshooting MySQL Replication Lag T"vkb-~q?6n0First fact you
absolutely need to remember is MySQL Replication is single threaded, which means
if you have any long running write query it clogs replication stream and small
and fast updates which go after it in MySQL binary log can't proceed. It is
either more than than just about queries - if you're using explicit transactions
all updates from the transactions are buffered together and when dumped to
binary log as one big chunk which can't be interleaved by any other query
execution. So if you have transaction containing millions of simple updates
instead of one large update to help MySQL replication lag it is not going to
work. This brings us
torule number
one- if you care about replication latency you must not have
any long running updates. Queries or transactions containing multiple update
queries which add up to long time. I would keep the maximum query length at
about 1/5th of the maximum replication lag you're ready to tolerate. So if you
want your replica to be no more than 1 minute behind keep the longest update
query to 10 sec or so. This is of course rule of thumb depending on differences
in master/slave configuration, their load and concurrency you may need to keep
the ratio higher or allow a bit longer queries. What should you
do if you need to update a lot of rows ? Use Query Chopping - this can be
running update/delete with LIMIT in the loop, controlling maximum amount of
values per batch in multiple row insert statement or Fetching data you're
planning to update/delete and having multiple queries to delete it (see example
below) This brings us
to yet another rule for smart replication - do not make Slave to do more work
than it needs to do. It is crippled by having to do all of this in single thread
already - do not make it even harder. If there is considerable effort needed to
select rows for modification - spread it out and have separate select and update
queries. In such case slave will only need to run
UPDATE木铎校园 BBS 社区V5w5eX"SZJ PLAIN TEXT SQL:
This query will
perform full table scan in MySQL 5.0 (even if there are no spam posts) which
will load slave significantly. You can replace it with: PLAIN TEXT SQL:
If there could
be many ids matched on the first place you should also use query chopping and
run update in chunks if application allows it. In MySQL 5.1
with row level replication you will not have selection process running on SLAVE
but it will not do the chopping for you. In general this
trick does not only work well for full table scan updates but in general for
cases when there are much more rows examined than
modified. Thenext common
mistakeis using INSERT ... SELECT - which is in similar to what
I just described but can be much worse as SELECT may end up being extremely
complicated query. It is best to avoid INSERT ... SELECT going through
replication in 5.0 for many reasons (locking, long query time, waste of
execution on slave). Piping data through application is the best solution in
many cases and is quite easy - it is trivial to write the function which will
take SELECT query and the table to which store its result set and use in your
application in all cases when you need this functionality. BMf}9rL7p;t0Finallyyou should not
overload your replication- Quite typically I see replication
lagging when batch jobs are running. These can load master significantly during
their run time and make it impossible for slave to run the same load through
single thread. The solution in many cases is to simply space it out and slow
down your batch job (such as adding sleep calls) to ensure there is enough
breathing room for replication thread. k2hE1` lozuZC0You can also
have controlled execution of batch job - this is when they will check slave lag
every so often and pause if it becomes too large. This is a bit more complicated
approach but it saves you from running around and adjusting your sleep behavior
to keep the progress fast enough and at the same time keep replication from
lagging. In many bad
replication lags I've seen simply following these simple rules would avoid a lot
of problems and often save massive hardware purchases or development efforts
based on assumption MySQL replication can't possibly keep up any
more. |
相关阅读:
- 让我介绍MySQL Master-Slave架构下使用MMM的必要性 (平凡的香草, 2008-2-18)
- MySQL Performance Tuning Primer Script (平凡的香草, 2008-3-07)
- How Mysql server use memory (平凡的香草, 2008-4-25)
- mysql HEAP MEMORY tables 提高行数支持的方法 zz (平凡的香草, 2008-4-29)

