补充一些有关mysql复制方面的资料

上一篇 / 下一篇  2008-10-22 16:01:53 / 个人分类:LAMP

有兴趣的可以参考:木铎校园 BBS 社区CI3];z*s1i

replication

%r4^v*Hx.zI0

Thoughts on MySQL Replication

LuG~ ]5[.M C0

http://www.mysqlperformanceblog.com/2006/07/07/thoughts-on-mysql-replication/

3|-{#\)@1\t0V0

 

dO9R]#G]]r0

Figuring out what limits MySQL Replication木铎校园 BBS 社区N8?2[i5lI/m-N

http://www.mysqlperformanceblog.com/2007/03/07/figuring-out-what-limits-mysql-replication/木铎校园 BBS 社区#L7w [j0J@&Q

 木铎校园 BBS 社区},@!Td9w _1ql

MySQL Replication and Slow Queries

K2| lF9jn6@oo0

http://www.mysqlperformanceblog.com/2007/03/28/mysql-replication-and-slow-queries/木铎校园 BBS 社区'k$JbO'THm0P(y

 木铎校园 BBS 社区6["p~-M+o7y}E.g+D7I

Replication will live!木铎校园 BBS 社区{d5gh?#K4[6J

http://dammit.lt/2008/04/12/replication-will-live/木铎校园 BBS 社区e7M+kc&@'Y c Z;f r5G

 

(@-c(nB h[ jb0

Managing Slave Lag with MySQL Replication

p6j7i(_;L%q cM%y0

http://www.mysqlperformanceblog.com/2007/10/12/managing-slave-lag-with-mysql-replication/木铎校园 BBS 社区[;C5l0W"ye\Pk

 木铎校园 BBS 社区$r\$})~#bii&I

OReIlly.High.Performance.MySQL.Second.Edition.Jun.2008.eBook-DDU.rar

$Vp$?k5`5N;F0

P367木铎校园 BBS 社区s6h+kH(k9E

 

M&|n6k0|3C0

MySQL Slave Delay Explained And 7 Ways To Battle It木铎校园 BBS 社区`1LQ h"C+i6L

http://beerpla.net/2008/09/05/mysql-slave-delay-explained-and-7-ways-to-battle-it/木铎校园 BBS 社区Q6l4I'zJ

 木铎校园 BBS 社区U K/t3q.?2X

Fighting MySQL Replication Lag木铎校园 BBS 社区jI.{zsn

http://www.mysqlperformanceblog.com/2008/09/22/fighting-mysql-replication-lag/

hz$e\[tL\.L0

 

/LGay/`;J1u"j-z_0

Three ways to know when a MySQL slave is about to start lagging

"_S/c4E,l5}|+f(^0

http://www.mysqlperformanceblog.com/2008/10/08/three-ways-to-know-when-a-mysql-slave-is-about-to-start-lagging/木铎校园 BBS 社区 YHF1N-hVm-]M_

 

1Ndx!|`2A0

数据库主从同步的延迟虽然看上去跟系统运维的关系更加密切,但对开发人员来说,了解如何避免或减少延迟,可以使得在设计之初就去考虑这类问题,最终解决方案也会更好

lYs5bo K)W}"Y:B3O0

 木铎校园 BBS 社区:u3BzY~6KLd!p

:MySQL Performance Blog木铎校园 BBS 社区4C"d:HK9bL OMW8s
投递时间:200892312:17木铎校园 BBS 社区4z@5[+].g}t E'DXd
作者:peter
T/@4Z3uDk0
主题:Fighting MySQL Replication Lag

w!E$nw.q Z!?:p&j0

 

*P:E C3CU-JFE M h!cZ0

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

C7L)@HU6k*S |R0

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.木铎校园 BBS 社区rS0{&|V?#B r0r

木铎校园 BBS 社区R(B~ fngd!L-z

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.

[J/DeO$ox0木铎校园 BBS 社区d'| ~I'?|x _

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)

s t0S rIhPP g B)f0木铎校园 BBS 社区Ri/y:`%Jk e5MV$td

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
Example:

C0c \9E5Ebv0

PLAIN TEXT

HO%GTMOb'[/u0

SQL:木铎校园 BBS 社区E| a.{L!Y ^7s

  1. UPDATEpostsSET  spam=1WHEREbodyLIKE"%cheap rolex%";
木铎校园 BBS 社区 R3|K6z4\ua2yb

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:

n9I I7L"b;r$mK0

PLAIN TEXT

O#RV'kKVE ?pO v i0

SQL:木铎校园 BBS 社区RE.V#hnp-z+Y

  1. SELECTidFROMpostsWHERE  bodyLIKE"%cheap rolex%";
  1.  
  1. UPDATEpostsSETspam=1WHEREidIN(list of ids)
木铎校园 BBS 社区+[S+TzDD2t

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.

U(|!AFU'd `!Fk0木铎校园 BBS 社区7V K__(ls

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.木铎校园 BBS 社区9?Y7oD;V k*x8X l.mK.b

木铎校园 BBS 社区e8A t7Ht

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.

i's~D:~7C.q0木铎校园 BBS 社区/hby,A PQ

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.木铎校园 BBS 社区/NM7[y.RdPF

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.木铎校园 BBS 社区{HyE~ K

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.

2i3Ek2u'ZNE%c0H0木铎校园 BBS 社区X2Ss)IJ l i

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.

.NF+U5ZemLy0

TAG: mysql MySQL Mysql 资料

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

关于作者