MySQLã«ã³ãã¡ã¬ã³ã¹2007 ï¼æ¥ç® ãªã¢ã«ã¿ã¤ã ã¬ãã¼ã
注ï¼ãã®ã¬ãã¼ãã¯ããªãã®å²åã§ã¹ã©ã¤ãã®å 容ã®åãã§ãã¨ãã©ã話ãã¦ãããã¨ã絡ãã¦ãã¾ããã¾ã¨ãããããããããªãã¦ãã¬ã¼ã³ã¹ã©ã¤ãã®å 容ããããã¾ã¨ã¾ã£ã¦ãã£ã¦ãã¨ã§ããã¼
MySQLã¦ã¼ã¶ã¼ã«ã³ãã¡ã¬ã³ã¹2007ã«æ¥ã¦ãã¾ããä¼å ´ã«ã³ã¨ã¹ï¼
- Larry社é·æ¥æ¬èªã§æ¨æ¶ä¸ãããã°ãã¼
- ã¹ããã¡ã³ã»ãã¬ã¼ã³é£ä¸ é§æ¥ã¹ã¦ã§ã¼ãã³å¤§ä½¿
- ã¢ã¸ã¢ã§MySQLã«ã³ãã¡ã¬ã³ã¹ãéãããã®ã¯åãã¦ã ãã
Matzæ°ç»å ´ - MySQLã«ã³ãã¡ã¬ã³ã¹2007
- ããã«ã¡ã¯ãRubyã®ã¾ã¤ãã¨ã§ãã
- MySQLã«è©³ãããªãã®ã«ãã©ããã¦ãæããªãã³ãã¯ã·ã§ã³ãéãã¦ä¾é ¼ãããã®ã§æ¥ã¾ããï¼ä¼å ´ç¬ï¼
- MySQLã®ãã¨ã¯ããããªããããªã¼ãã³ã½ã¼ã¹ã«ã¤ãã¦è©±ãã
- ã½ããã¦ã§ã¢ãç¡ä¾¡å¤ã ã£ãç§æçãªæ代ã®è©±ãã
ããªã¼ã½ããã¦ã§ã¢
èªç±ãªã½ããã¦ã§ã¢
- å®è¡ããèªç±
- å¦ç¿ããèªç±
- ä¿®æ£ããèªç±
- åé å¸ããèªç±
is GPL.
ãªã¼ãã³ã½ã¼ã¹(1998)
ãã¼ã±ãã£ã³ã°ç¨èª
- Netscape
- ãç¡åãã¤ã¡ã¼ã¸ããã®è±å´
- ä¼æ¥ã«ãããOSSã®æ´»ç¨
- ãæ°ããéçºã¹ã¿ã¤ã«ã
Just for Fun - ãããåã«ã¯æ¥½ããã£ããã : Linus Torbalds
Linux
- 趣å³ã§ã¹ã¿ã¼ã
- ä¸çä¸ã§æ®å
- å½åãããã¡ãã§ä½¿ããªãã
- ç¾å¨ã主è¦OSï¼ã®ã²ã¨ã¤ï¼ã
Ruby
- 趣å³ã§ã¹ã¿ã¼ã
- æè¡è ã«ã¯é«è©ä¾¡
- ãä»äºã«ã¯ä½¿ããªãã
Ruby on Rails
- é«çç£æ§
- ãä»äºã«ã使ããããã
From Java to Ruby
- Java(ã®ä¸é¨)ãç½®ãæãã
- å·éãªä»¥éæ¦ç¥
- æ°ããæè¡ã¸ã®ç±ãæã
ã¨ã³ã¿ã¼ãã©ã¤ãºOSS
æ
- ä¿¡é ¼ã§ããªã
- ç解ã§ããªã
- 使ããªã
ç¾å¨
- ãæ¡å¤ã使ããããã
- ãæ®åãã¦ãã
- ãæ´»ç¨ãã¦ãã
æªæ¥
- 主è¦ãªã³ã³ãã¼ãã³ã
- æ¬ ãããªã
- æåã¸ã®éµ
MySQLé«å¯ç¨æ§ã½ãªã¥ã¼ã·ã§ã³ã®æ¦è¦ - MySQLã«ã³ãã¡ã¬ã³ã¹2007
é«å¯ç¨æ§ã¨ã¯ï¼
- é害ãçºçãã¦ãã·ã¹ãã å ã®ãªã½ã¼ã¹ãå©ç¨å¯è½ãªç¶æ ã«ä¿ããããã¨
- ã«ãã´ãªã¯2ã¤
- ãã¼ã¦ã§ã¢
- ã½ããã¦ã§ã¢
- é£ç¶åè¦è«
- ç¡åæ¢ãµã¼ãã¹
- ãã§ã¤ã«ãªã¼ãæããµã¼ãã¹ãä¸æããªã
- é常ã«é«æ°´æºã®å¯ç¨æ§ï¼ä¸å¿ è¦ãªãã¨ãå¤ãï¼
- ãã©ã¼ã«ããã¬ã©ã³ã¹
- SPOF(Single point of failure)
- ãã§ã¤ã«ãªã¼ã
é«å¯ç¨æ§ã®è¦ä»¶ã¨å¿ è¦èæ ®äºé
- SLAï¼ãµã¼ãã¹å質ä¿è¨¼å¥ç´ï¼
- äºç®ã¨ç´åã¾ã§ã®ã¹ãã¼ã
- ã»ãã¥ãªãã£
- ã¹ãã¬ã¼ã¸ã®æ¤è¨
- ãããã
ã¹ã±ã¼ã«ã¢ããã¨ã¹ã±ã¼ã«ã¢ã¦ãã®éã
MySQLã¯ã¹ã±ã¼ã«ã¢ã¦ãå
- ã¹ã±ã¼ã«ã¢ãã
- åç´ç
- é«ä¾¡
- ã¹ã±ã¼ã«ã¢ã¦ã
- æ°´å¹³ç
- OSS
ã¬ããªã±ã¼ã·ã§ã³ã¨ã¯ï¼
- è¤æ°ã®å ´æã¸ã®ãã¼ã¿è¤å
- éåæåã¨åæå
- MySQL Replication
- ã¹ãã¼ãã¡ã³ãï¼å¯¾ï¼è¡ãã¼ã¹ã®ã¬ããªã±ã¼ã·ã§ã³
- ãããã¯ã¬ãã«ã§ã®ã¬ããªã±ã¼ã·ã§ã³(DRBD)
ã¯ã©ã¹ã¿ãªã³ã°ã¨ã¯ï¼
- ããã³ã³ãã¼ãã³ãã«åé¡ãèµ·ããã¨ãåé·ãã¼ãããµã¼ãã¹ãæä¾
MySQL Clusterã®è§£èª¬
- ã¹ã©ã¤ãä¸å¿ãªã®ã§å²æ
- ã¹ã©ã¤ãã¯ãã¦ã³ãã¼ãå ¬éãããã¯ã
DRBDããã³ Heartbeat ã«ããé«å¯ç¨æ§MySQLï¼MTVã¸ã£ãã³ãã¢ãã¤ã«ãµã¼ãã¹ - MySQLã«ã³ãã¡ã¬ã³ã¹2007
MTV Flux/MTV Mobile DB projectã«ãããMySQLæ§æã®è©±
DR:BD/Heartbeat HA Master æ§æ
- ã¹ã±ã¼ã«çã«ã¯Single Masterããã¡ãã£ã¨ãã
- ã¢ããªã«é¢ãã¦
- Single masterã¨ã»ã¼ãã£ãã
- ãã§ã¤ã«ãªã¼ãã¼ãååæ©ãã®ã§ããããå½±é¿ããªã
- Heartbeatã«é¢ãã¦
- è¨å®ã大å ééãã®ä½è£ããªã
- peerã®æ¥ç¶ãç¹ã«æ³¨ç®ç¹
- æ¬çªåããåã«ãã¹ã
- mysqld
- ãã¼ã移管ãç°¡å
- ãã©ã¤ããªã¨ã»ã«ã³ããªã®mysqlãåæèµ·åããªããã¨ã大å
- Heartbeatã«ãã¾ãã
- DR:BD
- æ¢åã·ã¹ãã ã«å°å ¥ã®å ´åããã£ã¹ã¯ã®ã¬ããªã±ã¼ã·ã§ã³ãå¿ è¦
- åããç解ããããååæ¤è¨¼ããã¨ãã
- ã¢ã¦ãã¼ã¸ããã£ãå ´åãdrbdã¹ãã¼ã¿ã¹ã®ç¢ºèªãå¿ è¦
ããã£ããã¨
æªãã£ããã¨
- åå¼·ãæ¤è¨¼ã«æéããããå¿ è¦ããã
- è¨å®ãã½ããã®é¢é£æ§ãè¤é
- mysqldããã»ã¹ã®åèµ·åã¯ã·ã³ãã«ã§ã¯ãªã
- éç¨ã®é¢ä¿è ãè¨å®ãåããç解ããªãã¨ãããªã
MySQL ããã©ã¼ãã³ã¹ãã¥ã¼ãã³ã°&ãã³ããã¼ã¯ - MySQLã«ã³ãã¡ã¬ã³ã¹2007
http://www.mysql-ucj2007.jp/details/e13.html
Agenda
- An introduction to Benchmarking
- data structures
- query optimisation and query cache
- etc..
Why Benchmark?
The Good Scientists Guide to Benchmarking
- The scientific method suggests changing only one variable at a time
- The scientific method suggests repetition, more than once to verify results. If results vary greatly, think about taking averages
- Repeat, rinse , repeat , rinse!
- å°ãªãã¨ã3åã¯ã
The Good Scientists Guide to Benchmarking II
- Isolate your environment
- Use a different MySQL instance
- Savle all configurations!
Benchmarking Tools
Benchmarking Tools II
Slow Query Log
- log_slow_queries=/var/lib/mysql/slow-queries.log
- long_query_time=2
- Then, use mysqldumpslow
- In 5.1, you can log these details ...
-
-
EXPLAIN basics
- Provides the execution plan chosen by the MySQL optimiser for a...
ããªã³ã©ã¤ã³ã§èªãã§ã
EXPLAIN columns
- select_type
- table
- ...
ããªã³ã©ã¤ã³ã§èªãã§ã
Scans and seeks
- A seek, jumps into a random place to fetch needed data.
- A scan will jump to the start of the data...
When do you get a full table scan?
- No WHERE conditions
- No index on any field in WHERE condition
- When your range returns a large number of rows, i.e. too many records in WHERE condition
- Pre-MySQL 5, using OR in a WHERE clause
- SELECT * FROM
Subqueries
- Don't use them; replace with a JOIN
- unique_subquery: results are known to be distinct
- index_subquery: otherwise
- Co-related subqueries are worse
- ...
Indexes
Good Schema Practice
- Use small data types
- Is a BIGINT really required?
- Small data types allow more index and data recoreds to fit into a single block of memory
- Normalise first, de-normalise later
- Generally, 3NF works pretty well
æ£è¦åããããªãã
Storing IP addresses
- IP addresses always become an INT UNSIGNED
- Each subnet corresponds to an 8-byte division of the underlying INT UNSIGNED
- From string to int? Use INET_ATON()
- From into to ...
Query Cache
- ã¹ã©ã¤ã
- ããããã®ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ããã
- Understand your applications read/write ratio for most effective use
- Compromise between CPU usage and read performance
- Remember that the bigger your query cache, you may not see better performance, even if your application is read heavy
Query Cache Invalidation
ãã£ãã·ã¥ã®ç¡å¹å
- Coarse invalidation designed to prevent CPU overuse
- ...
- Thusm any modification to any table referenced in the SELECT will invali...
Choosing a Storage Engine
- MySQLs strong point: many engines MySQLã¯ããããã¨ã³ã¸ã³ãããã
- Use InnoDB for most operations (esp. OLTP), except:
- big, read only tables
- high volume streaming tables(logging)
- specialised needs (have special engines)
- Tune InnoDB wisely
PBXãããã°ã¨ãã«ããã
Quick InnoDB Tuning Tips
Real World MySQL Use (RWMU)
- Run many servers
- Your serious application cannot run on "the server"
- "Shared nothing" architecture
- make no single point of contention in the system
- Scales well, just by adding cheap nodes
- If it works for Google, it will work for you!
RWMU: State and Session Information
- Dont keep state within the application server
- Key to being stateless: session data
- Cookies are best validated by checksums and timestamps(encrypting is a waste of CPU cycles)
RWMU: Caching
RWMU : Data Partitioning
- replication is great for read heavy applications
- Write intensive applications should look at partitioning
- Partition with a global master server in mind
- Give out global PKs and cache heavily (memcached)
- ...
- Consider the notion of summary databases
RWMU: Blobs
- Large binary object storage is interesting
- Image data is best kept in the filesystem, just use metadata in DB to reference server and path to filename
- Try the Amazon S3 storage engine?
- ...
RWMU: Misc.tips
- Unicode - use it Unicodeã¯ããå½ããå
- ããã°ã§ä½¿ãããè¨èªã¯æ¥æ¬èªãæãå¤ããã
- Use UTC for time
- Think about replication across geographical boundaries
- sql_mode might as well be strict
- Keep configuration in version control
- Then consider puppet or slack for management of various servers
Resources
services
- http://www.mysql.com/training/
- æ¥æ¬èªã«ãããèªå®ãä»ææ«(2007å¹´9ææ«)ããå§ã¾ã
æ°ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ Falcon ã®ã¢ã¼ããã¯ãã£è©³ç´°æè¡è§£èª¬ - MySQLã«ã³ãã¡ã¬ã³ã¹2007
MySQLã¢ã¼ããã¯ãã£ã®è§£èª¬
- ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ããã©ã¬ãã«
- 5.1ã§ã¯å ±æã©ã¤ãã©ãªåãã¦åçã«çµã¿è¾¼ããããã«ãªã
- InnoDBã®ãããã«falconã使ã
Falconã¨ã¯
- MySQL ABã«ããç¾å¨éçºä¸ã®ããã©ã³ã¶ã¯ã·ã§ã³å¯¾å¿ã®ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³
- éçºä¸ã§å®æãã¦ãªããalphaç
- Jim Starkeyæ°ãä¸å¿ã«éçº
- InnoDBãã»ã¼å ¨ã¦ã®ç¹ã§ä¸åããã¨ãç®æãã¦ãã
- ã¾ããªããã¼ã¿çãç»å ´ã
- MySQL 6.0ã§å®å®çãæè¼äºå®
- ææ³ï¼ç¾ä»£çãªãã¼ãã¦ã§ã¢ç°å¢ããã«æ´»ç¨ã§ããRDBMSãç®æã
- ãã«ãã³ã¢CPU
- 大容éã¡ã¢ãª
- ä½éãªãã£ã¹ã¯ãRAID
InnoDBã¨ã®ä¸»ãªå·®ç°
- ã¯ã©ã¹ã¿ç´¢å¼ãæ¡ç¨ãã¦ããªã
- è¡ãã¼ã¹ã®ã¬ããªã±ã¼ã·ã§ã³(Binary Logging)ã®ã¿ããµãã¼ãããæãã¼ã¹ã®ã¬ããªã±ã¼ã·ã§ã³ããµãã¼ãããªã
- åé¢ã¬ãã«ãRead uncommittedãããµãã¼ãããªã
ã»ãã®ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã¨ã®æ¯è¼
å³
Falconã®ã¢ã¼ããã¯ãã£æ¦ç¥
- 4ã¤ã®ã¡ã¢ãªé åã«åãã¦éè¨ Record Cache, Page Cache, Log Cache, System Cache
- ã§ããã ãå¤ãã®ã¬ã³ã¼ããRecord Cacheã«ä¹ãããã«ãã¦ãã
- Record Cacheã¯Page Cacheããããªã¼ãã¼ããããå°ãªã
ããã»ã¹/ã¹ã¬ãã
- MySQLã¯ãã«ãã¹ã¬ããåã¢ã¼ããã¯ãã£
- æ¥ç¶1åã«å¯¾ãã¦ã¹ã¬ããã1åå²ãå½ã¦ã¦åä½
- Falconå°å±ã®ãããã¯ã°ã©ã¦ã³ãã§åä½ããã¹ã¬ããããã
- ãã§ãã¯ãã¤ã³ãã®å®è¡
- ãã£ãã·ã¥ç®¡çï¼å¤ãã¬ã³ã¼ãã®éé¿ãªã©ï¼
- mutexãã©ããã³ã°ãã¦æä»å¶å¾¡ (SyncObjects)
- Read/Writeããã¯ãå°å ¥
- Readã¯ä»ã®Readããããã¯ããªãï¼â»è¡ã¬ãã«ããã¯ã¨ã¯å¥ç©ï¼
- åæå®å¹æ§ã大ããé«ããå¹æããã
- ãã«ãCPUã³ã¢ç°å¢ã§éè¦ãªæè¡
ãã¡ã¤ã«ã®èªã¿æ¸ã
ã·ãªã¢ã«ãã°ãã¡ã¤ã«ããã¼ã¿ãã¡ã¤ã«
- ã·ãªã¢ã«ãã°ãã¡ã¤ã«ã¯REDOãã°ã«ç¸å½ããã ãããµã¤ãºã¯åºå®ã§ã¯ãªã
- æªã³ãããã®æ
å ±ã¯ãã¼ã¿ãã¡ã¤ã«ã«æ¸ãããªã
- ãã¼ã«ããã¯ã®é«éå
- ã©ã³ãã I/Oã®åæ°ãæ¸ã
- ã³ãããããæ å ±ã¯æçµçã«ãã¼ã¿ãã¡ã¤ã«ã«åæ ããã
- Falconã®ãã°ã«ã¼ãã³ããããæ©è½ã¯ãããã¦é«æ§è½
表é åï¼ãã¼ãã«ã¹ãã¼ã¹ï¼
ã¤ã³ããã¯ã¹æ§æ
- ã«ã¼ã -> ãã©ã³ã -> Leaf
- ã¯ã©ã¹ã¿ç´¢å¼/ã»ã«ã³ããªç´¢å¼ã¨ããåºå¥ã¯ãªããå ¨é¨ãã®å½¢
- RecordNumberã¯ç¾å¨4ãã¤ãåºå®ï¼å®å®çã¾ã§ã«å¤æ´äºå®ï¼
- ããã«ã¤ã³ããã¯ã¹ãµã¤ãºã¯ï¼ã¯ã©ã¹ã¿ç´¢å¼ã«æ¯ã¹ã¦ï¼ãã»ã©å¤§ãããªããªã
- ãã¼ã¸ã¯I/Oã®æå°åä½ããµã¤ãºã¯å¯å¤ï¼2KB-32KBã¨ãªã£ã¦ãããå®å®çã¾ã§ã«ã©ããªããã¯ããããªãï¼
ã¤ã³ããã¯ã¹å¤ã®å§ç¸®
- æ¥å°¾è¾ã®å§ç¸®
- æ°å¤åï¼æ«å°¾ã®ã¼ããå§ç¸®
- æåååï¼æ«å°¾ã®ç©ºç½ãå§ç¸®
- æ¥é è¾ã®å§ç¸®
- åãã¼ã¸ã®å é ã®ã¤ã³ããã¯ã¹å¤ã¯å§ç¸®ããªã
- 2çªç®ä»¥éã®ã¤ã³ããã¯ã¹å¤ã¯ãéå§ä½åã¨ãå é ã®ã¤ã³ããã¯ã¹å¤ã¨ä¸è´ãããã調ã¹ããã®åãå§ç¸®ãã
- ãã¾ãããã¨60%ãããå§ç¸®ã§ãã
- å§ç¸®å¦çãããã®ã§å½ç¶CPUã¯ä½¿ã£ã¡ãããon/offåãæ¿ãå¯è½ã«ãããæ¤è¨ä¸
ã¤ã³ããã¯ã¹ã¢ã¯ã»ã©ã¬ã¼ã¿
- commitæã«ã¤ã³ããã¯ã¹ãåæ ãã
- rollbackã®ãªã¼ãã¼ããããæ¸ã
- å¤å°æ¤ç´¢å¦çããªã¼ãã¼ãããã«ãªã
- 以åãã³ããã¼ã¯ããã¨ãã¯ããã«ããã¯ã«ãªã£ã¦ãããä»ã¯å¤§åæ¹åããã
ã¬ã³ã¼ãã®åå¾
- ã¤ã³ããã¯ã¹ãæ¤ç´¢ããã¬ã³ã¼ãçªå·ãåå¾
- ã¬ã³ã¼ãçªå·ããå®éã®ã¬ã³ã¼ããåå¾
- ã¡ã¤ã³ã®ã¬ã³ã¼ãã®åå¾ã¯ãã£ãã·ã¥ããè¡ããã
ãã¼ã¿åã¨æ¶è²»ãµã¤ãº
Falconã¯TEXT/BLOBåãå¥ã¡ã¢ãªé åã«ç®¡çãã
AUTO_INCREMENTã®åä½ã®éã
ãã©ã³ã¶ã¯ã·ã§ã³ãããã¯ãMVCC
- è¡ã¬ãã«ãããã³ã°
- SELECTã¯ããã¯ããããªããæ´æ°ç³»å¦çã¨ç«¶åããªããInnoDBãåã
- ãããã¯ããSELECT FOR UPDATEããµãã¼ã
- AUTO_INCREMENTã®å²ãå½ã¦ã«ãã¼ãã«ããã¯ããããªã
- éããªãã®ã§ã5.1ã§æ¹åããã
- åé¢ã¬ãã«ã¨ãã¦Read Commited, Repeatable Readããµãã¼ã
- Serializableããµãã¼ãäºå®
- ããã¯ã¨ã¹ã«ã¬ã¼ã·ã§ã³ã¯çºçããªããInnoDBãåã
- ãããããã¯ã®æ¤ç¥ã¯èªåã§è¡ã
- ããã¯ããããªãã«ã©ã ãã¤ã³ããã¯ã¹ã®è¿½å /åé¤
- ãã¹ãã¢ãããã¼ãã®èªåæ¤ç¥
- Next Keyãããã³ã°ã¯çºçããªã
ãã¹ãã¢ãããã¼ãã®èªåæ¤ç¥
- ãã¹ãã¢ãããã¼ãã¨ã¯
- Falconã®åä½ããè¨å®ã§InnoDBã¨åãã«ãããã¨ãã§ããï¼ããã©ã«ãã§åä¸ã«ããæ¹åï¼
Next-Key Lockingã¨ã¯ (InnoDBã®ããã¯å¶å¾¡)
- InnoDBãã°ãã¡ã¤ã«ã¨ãã¤ããªãã°ã®ä¸æ´åãã£ãµããããã«å¿ è¦ãªå®è£
- Insert INTO t1 .. SELECT .. FROM t2
- t2ã«å¯¾ãã¦å ±æããã¯ãããã
- UPDATE t1 SET xx WHERE non_index_column=x;
- ãã«ãã¼ãã«ã¹ãã£ã³ã«ãªããã¹ãã£ã³ããã¬ã³ã¼ãå ¨ä½ã«å¯¾ãã¦æä»ããã¯ãããã
- UPDATE t1 SET xx WHERE non_unique_index_column=x;
- å½è©²ã¤ã³ããã¯ã¹ã¨ããã®åå¾ã«å¯¾ãã¦æä»ããã¯ãããã
- ã»ãã·ã§ã³ï¼:INSERT INTO t1 SELECT * FROM t2
- ã»ãã·ã§ã³ï¼:INSERT INTO t2 VALUES(...)
- ã»ãã·ã§ã³2ãã»ãã·ã§ã³1ãããåã«çµãã£ãã¨ãã
- ãã¤ããªãã°ã®ä¸èº«ã¯ãé çªãé転ãã
- Next-Key Lockingã¯ãããé²ãããã®å®è£
Falconã§ã¯Next Key Lockingã¯çºçããªã
- åæå®å¹æ§ã®ä½ä¸ã¯5.1ã§åé¿ããã
åèè³æ
- ãã¤ã³ãã¸ã£ã¼ãã«ï¼ Falconå¾¹åºãªãµã¼ã
- MySQL Developer Zone: Falcon in depth ãã¼ã¿çãªãªã¼ã¹å¾ã«å ¬é
- MySQLãªã³ã©ã¤ã³ããã¥ã¢ã«ã«ã¦ http://dev.mysql.com/doc/falcon/en/index.html
- MySQL Forge http://forge.mysql.com/wiki/Falcon