Ruby/MySQL 2.9.9 ãä½ãã¾ããã
Ruby/MySQL
Ruby/MySQL 㯠Ruby ãã MySQL ã使ç¨ããããã®ã©ã¤ãã©ãªã§ãã
ç¹å¾´:
- Ruby ã ãã§æ¸ããã¦ããããã³ã³ãã¤ã«ä¸è¦
- Ruby 1.9 ã® Encoding 対å¿
- Ruby ã®ã¹ã¬ããã§ãåä½
- MySQL C API ã©ã¤ãã©ãª(libmysqlclient)ã使ç¨ãã¦ããªã
- é ã
ä»åã®ãªãªã¼ã¹ã¯ä¸»ã«é度æ¹åã§ãã
ã¤ã³ã¹ãã¼ã«
% gem install ruby-mysql
é度æ¹åã®ããä¸é¨ãCã§æ¸ãã ruby-mysql-ext ã¨ããã®ãããã¾ãã
ãã¡ãã¯ãã¤ã³ã¹ãã¼ã«ããããã«ã³ã³ãã¤ã«ãå¿
è¦ã§ãã
% gem install ruby-mysql-ext
é度
ç°¡åã«é度ã測ã£ã¦ã¿ã¾ãããã¡ããã¨æ¸¬ã£ã¦ãªãã®ã§é°å²æ°ã§ãã
(select ã®çµæãæ£ãããªãã£ãã®ã§åãç´ãã¾ãã)
è¨æ¸¬ç°å¢:
ThinkPad X220 Core i5-2410M Memory 8GB Ubuntu Linux 12.04 MySQL 5.5.25 Ruby 1.9.3p194 / 1.8.7p352
ã°ã©ãã®ç¸¦è»¸ã¯ç§ã§ãã
å¦çå 容ã¯ãããªæãã§ãã詳細㯠https://github.com/tmtm/ruby-mysql/tree/master/bench ãè¦ã¦ãã ããã
- insert
- 10ä¸ã¬ã³ã¼ãã®INSERT
- insert(prepare)
- 10ä¸ã¬ã³ã¼ããããªãã¢ãã¹ãã¼ãã¡ã³ãã§INSERT
- select
- 10ä¸ã¬ã³ã¼ãã®SELECT(10000ã¬ã³ã¼ãã10å)
- select(prepare)
- 10ä¸ã¬ã³ã¼ããããªãã¢ãã¹ãã¼ãã¡ã³ãã§SELECT(ã)
- many_query
- çµæãè¿ããªãã¯ã¨ãªã10ä¸åçºè¡
ã°ã©ãä¸ã® MySQL/Ruby ã¨ããã®ã¯ MySQL ã® C APIã©ã¤ãã©ãª libmysqlclient ã使ç¨ãããã®ã§ãããã¹ã¦ C ã§æ¸ããã¦ãããããã£ã±ãéãã§ãã
æéãªç°å¢ãæ±ããã®ã§ããã° MySQL/Ruby ã使ãã®ãããã¨æãã¾ãããä»å¾ã¯ããããã¡ã³ãããã¾ãããmysql2 ã¨ããã©ã¤ãã©ãªãããã®ã§ããã使ãã®ãããã¨æãã¾ãã
ãã«ãã¹ã¬ãã
Ruby/MySQL 㯠Ruby ã§æ¸ããã¦ãããããRuby ã®ã¹ã¬ããã使ç¨ãã¦ãæéããããã¯ã¨ãªå®è¡ä¸ã§ãå¥ã®å¦çãè¡ããã¨ãã§ãã¾ããä¸é¨ C ã§æ¸ããã Extçã§ããã¹ã¬ããåãæ¿ãã妨ãã¦ããããªãã¨ã¯ãã¦ããªãã¤ããã§ãã
ãã¨ãã°æ¬¡ã®ã¹ã¯ãªããã Ruby/MySQL ã§å®è¡ããã¨ãã¯ã¨ãªå®è¡ä¸ã®5ç§ã®éã§ãã¹ã¬ãããåãã¦æ°åãåºåãã¾ãã
require 'mysql' my = Mysql.new('localhost', 'root', 'password') Thread.new do 10.times do |i| p i sleep 1 end end my.query('select sleep(5)') # 5ç§æããã¯ã¨ãª
MySQL/Ruby ã使ç¨ããå ´åã¯5ç§éä½ã表示ããã«çµäºãã¦ãã¾ãã¾ãã
Extç(ä¸é¨ Cç)ã®æ³¨æ
å é¨ã§ã¨ã³ãã£ã¢ã³ã«ä¾åããç®æãããã®ã§ãããæå ã«ããã°ã¨ã³ãã£ã¢ã³ç°å¢ããªããã試ãã¦ã¾ããã
GCC ã§ããã³ã³ãã¤ã«ãã¦ãªãã®ã§ãä»ã®ã³ã³ãã¤ã©ã§ã³ã³ãã¤ã«ã§ãããã©ãããããã¾ããã
Windows ç°å¢ã§ã¯åããªããããªæ°ããã¾ãããªãã¨ãªãã