PDOããé«éãªORMã©ã¤ãã©ãª! Transactd PHP ORM ãªãªã¼ã¹
2016å¹´12æ22æ¥ã«Transactd PHP ORMããªãªã¼ã¹ãã¾ããã
ããã¯Transactdã使ç¨ããMySQL/MariaDBç¨ã®ORMã©ã¤ãã©ãªã§ãã
ä»åã¯ãã®Transactd PHP ORMãç´¹ä»ãã¾ãã
Contents
主ãªç¹å¾´
é«éãªDBã¢ã¯ã»ã¹
Transactd PHP ORMã¯ãORMã§ãããªããPDOãç´æ¥ä½¿ç¨ããã¢ã¯ã»ã¹ãããé«éãªãã¼ã¿ã¢ã¯ã»ã¹ãã§ãã¾ãã
ä¸å³ã¯ãTransactdã¨PDOãLaravel EloquentORMã§ãfind
ã¡ã½ããã«ãã1ã¬ã³ã¼ãã¢ã¯ã»ã¹ãï¼ç°ãªãidã§ï¼100åè¡ã£ãã¨ãã®æéãè¨æ¸¬ããçµæã§ããPDOã¯SELECT * FROM table WHERE id=x
ã§è¨æ¸¬ãã¦ãã¾ãã
Transactdã¯PDOã®ç´2åãLaravelã®5.3åé«éã«å¦çãã¦ãã¾ãã
ï¼100åã«ã¼ããããã¨ã§ãã¯ã©ã¹ã®ãã¼ãæéãªã©ã®å½±é¿ãå°ããããç´ç²ãªãã¼ã¿ã¢ã¯ã»ã¹ã«ãããæéãæ±ãã¾ãããï¼
é常ãPHPã®ORMã¯PDOã使ã£ã¦å®è£ ããã¾ãããããã¯å¿ ãPDOãã¤ãã£ãããé ããªãã¾ããMySQLã«å¯¾ãã¦ãPDOããé«éã«åä½ããã®ã¯ããããTransactd PHP ORMã ãã§ãããã
çã¡ã¢ãª
Transactd PHP ORMã¯ãä»ã®ORMã«æ¯ã¹ã¦é常ã«å°ãªãã¡ã¢ãªã§åä½ãã¾ããèªã¿åã£ãã¢ãã«ã®æ°ã«ãããã¾ããã1ã¤ã®ã¢ãã«ã§Laravel 5.3ã®1/5ç¨åº¦ãå¤ãã®ã¢ãã«ã§ã1/2以ä¸ã®ã¡ã¢ãªä½¿ç¨éã§ãã
ä¸ã®è¡¨ã¯ãä¸è¨ã®ãã¹ãã®åå¾ã«ããã¦memory_get_usage
é¢æ°ã§ä½¿ç¨ã¡ã¢ãªã®å¢åãè¨æ¸¬ãããã®ã§ãã
Transactd | PDO | Laravel | |
---|---|---|---|
ã¡ã¢ãªå¢å é (KB) | 81 | 459 | 442 |
é«ã¹ã«ã¼ããã
é«éãªDBã¢ã¯ã»ã¹ã¨çã¡ã¢ãªã«ãã£ã¦ãé«ãã¹ã«ã¼ããããå®ç¾ã§ãã¾ããWebãªã¯ã¨ã¹ãã«å¯¾ããã¹ã«ã¼ãããã¯ãå¦çå ¨ä½ã«å¯¾ãããã¼ã¿å¦çã®æ¯çã«ãã£ã¦å¤ããã¾ãããæ¯è¼çãã¼ã¿å¦çãéãã±ã¼ã¹ã§ã¯ãLaravel 5.3ã«æ¯ã¹ã¦2å以ä¸ã®ã¹ã«ã¼ããããå®ç¾ãã¦ãã¾ãã
ä¸å³ã¯ãApache JMeterã使ã£ã¦Laravelãã¬ã¼ã ã¯ã¼ã¯ä¸ã«EloquentORMã¨Transactd PHP ORMã§åãå
容ã®ã¢ãã«ãåä½ãããå¦çæéãè¨æ¸¬ããçµæã§ãã
è¨æ¸¬ãã¼ã¸ã¯2ã¤ã®ãªã¬ã¼ã·ã§ã³ãæã£ã200åã®ã¢ãã«ããã¼ãã«å½¢å¼ã«ããHTMLãè¿ãã¦ãã¾ãã
ç¾å®çãªã¬ã¹ãã³ã¹æéãç´300msec以ä¸ã¨ããã¨ãã¹ã«ã¼ãããã¯Laravelã§ç§é20ã¯ã©ã¤ã¢ã³ããTransactdã§ã¯40ã¯ã©ã¤ã³ãã§ãç´2åã«ãªã£ã¦ãã¾ãã
åãLaravelã®ãã¬ã¼ã ã¯ã¼ã¯ä¸ãªã®ã§ãç°ãªãã®ã¯ORMã®ã¿ã§ããORMãå¤ãããã¨ã§Webå
¨ä½ã®ã¹ã«ã¼ããããåä¸ã§ãããã¨ããããã¾ãã
é«å¯ç¨æ§
ããã©ã«ãã§ããã¹ã¿ã¼ã»ã¹ã¬ã¼ãæ§æã§ãèªã¿åããã¹ã¬ã¼ããæ¸ãè¾¼ã¿ããã¹ã¿ã¼ã«æ¯ãåããæ©è½ãããã¾ããã¾ããTHAã«ããé«å¯ç¨éç¨ãå¯è½ã§ãã
èªå¨ãªãã©ã³ã¶ã¯ã·ã§ã³ã¨ããã¯ãã¹ãããã·ã§ãã
Transactdã«ã¯ã1ã¬ã³ã¼ããã¤ã¤ã³ããã¯ã¹é ã«èªå¨ã«ã¢ã¯ã»ã¹ã§ããサーバーカーソルãããã¾ãããµã¼ãã¼ã«ã¼ã½ã«ã使ãã¨ç´°ããªè¡ããã¯ã¨ãã©ã³ã¶ã¯ã·ã§ã³ã®å¶å¾¡ãå¯è½ã§ãã
ã¾ããä¸è²«æ§èªåã®ããã®ã¹ãããã·ã§ãããç°¡åã«è¡ãã¾ãã
ããã·ã§ã³ã¯ãªãã£ã«ã«ãªã¢ããªã±ã¼ã·ã§ã³ã«ãæé©ã§ããããã¯ã¨ãã©ã³ã¶ã¯ã·ã§ã³ã«ã¤ãã¦ã¯ãMySQL/MariaDBとTransactdのInnoDBロック制御詳細 その1 - BizStationブログãåç
§ãã¦ãã ããã
詳細ãªããã¥ã¡ã³ã
ドキュメントãã©ã¤ãã©ãªã®ä¸é¨ã§ããã¨ã«ããåããããããªãããåªåãã¾ããã
ç¹ã«販売管理のサンプルアプリケーションã§ã¯ãå®éã«åä½ããã¢ããªã±ã¼ã·ã§ã³ãä½æããªãããããã·ã§ã³ã¯ãªãã£ã«ã«ãªãã¤ã³ãã«éç¹ãç½®ãã¦èª¬æãã¦ãã¾ããORMã使ããªãã¦ããMySQLã使ç¨ãã¦ããæ¹ã«ã¯åèã«ãªãç¹ããããã¨æãã¾ãã
æ¬ ç¹
æ¬ ç¹ã¯ãç¾å¨ã®ã¨ãããã¤ã°ã¬ã¼ã·ã§ã³ããµãã¼ãããã¦ããªããã¨ã§ãããã ããã¼ã¿ãã¼ã¹ãMySQLãªã®ã§ããã¬ã¼ã ã¯ã¼ã¯ã«ãã¤ã°ã¬ã¼ã·ã§ã³ãããã°ããããã®ã¾ã¾ä½¿ç¨å¯è½ã§ãã
詳細
ãã§ã«ORMã使ç¨ããã¦ããæ¹åãã«ãORMã®ä¸è¬çãªåé¡ã«ã¤ãã¦ã®Transactdã§ã®å¯¾å¿å 容ã説æãã¾ãã
ORMã¤ã³ã¿ã¼ãã§ã¼ã¹
ORMのAPIインタフェースã¯ãRuby on Railsã®æµããæ±²ãã Laravel 5ã«é常ã«è¿ããã®ã§ããTransactdã®ãã¤ãã£ãAPIã¨ORMã¯é常ã«ç¸æ§ãè¯ããå°ãªãã³ã¼ãã§ORMãæ§æãã¦ãã¾ããã¢ãã«ã®çæã¯C++ã§å®è£ ãããã¨ã¯ã¹ãã³ã·ã§ã³å ã§è¡ãããé常ã«é«éã«å¦çããã¾ãã
ãªã¬ã¼ã·ã§ã³ã®ãã¼ãã¿ã¤ãã³ã°
Transactd PHP ORMã®ãªã¬ã¼ã·ã§ã³ã¯ããã©ã«ãã§ãã¢ã¯ã»ã¹æã«ãã¼ãããé
延ãã¼ãã§ããã¾ããã¢ãã«ã®ã³ã¬ã¯ã·ã§ã³ã®ãªã¬ã¼ã·ã§ã³ãä¸æ¬ãã¦åå¾ããEager loading
ããµãã¼ããã¦ãã¾ãã
åèï¼モデル - パフォーマンス
ã¤ã³ãã¼ãã³ã¹ãã¹ããã
ãã¼ãã«ã¨ã¢ãã«ã§æ±ãé åãç°ãªããã¨ããã¤ã³ãã¼ãã³ã¹ãã¹ãããã¨å¼ã³ã¾ããTransactdã§ã¯ããã¼ãã«ã®ãã£ã¼ã«ããã¨ã«ãå¥ã®ã¯ã©ã¹ã®ããããã£ã¸ã®ãããã³ã°ãæå®ãããã¨ã§ãORMã«å¤ã®èªã¿æ¸ããããããã¨ãå¯è½ã§ãã
åèï¼モデル - インピーダンスミスマッチ
ã¢ãã«ã®ãã£ãã·ã¥
find
ã¡ã½ããã使ç¨ããã¦ãã¼ã¯ãªãã¼å¤æ¤ç´¢ã¯é »ç¹ã«çºçãã¾ããã¾ãããã®å¤ã¯ãã¾ãå¤åããªãå ´åãå¤ãããã®é½åº¦ãã¼ã¿ãã¼ã¹ã«ã¢ã¯ã»ã¹ããã®ã¯ç¡é§ãå¤ããªãã¾ããããã§Transactd PHP ORMã§ã¯ããã®ãããªã¢ãã«ããã£ãã·ã¥ããæ¤ç´¢æã«ã¯ãã£ãã·ã¥ãããã°ãããè¿ãã¾ãã
ãã£ãã·ã¥ã®å¹æã¯é常ã«å¤§ãããæ°ååã®é度ã¢ããã«ãªããã¨ãããã¾ãã
åèï¼モデル-キャッシュ
IDEã®ã³ã¼ãè£å®æ¯æ´
ã¢ãã«ã®ããããã£ã¯ãã¢ãã«å
ã«æ示çã«å®£è¨ããå¿
è¦ãããã¾ãããè¨è¿°ãç°¡åãªåé¢ãéçºç¨ã®IDEããã¯ã©ã®ãããªå±æ§ãããã®ãããããªããªãã¾ãã
Transactd PHP ORMã§ã¯ãã¢ãã«ã®ã½ã¼ã¹ã³ã¼ãã¸ã§ãã¬ã¼ã¿ãPHPDocã«å¯¾å¿ãã@property
ã³ã¡ã³ããåºåãã¾ããããã«ããIDEã§ã®ã³ã¼ãè£å®ãå¯è½ã«ãªãã¾ãã
åèï¼モデル-自動生成
ããããã£ã¢ã¯ã»ã¹é度
PHPã§ã¯ãããããã£ã®å®è£ ã§ãã¸ãã¯ã¡ã½ããã使ããã¨ãã§ãã¾ãããããããã®æ¹æ³ã¯é常ã«ä½éã§ããTransactd PHP ORMã¯é常ã®ããããã£ã®å®è£ ã«ãã¸ãã¯ã¡ã½ããã使ç¨ãã¾ããããã¼ã¿ãã¼ã¹ã¢ã¯ã»ã¹ã®é«éåã ãã§ãªããããããã£ã¢ã¯ã»ã¹é度ã«ããã©ã¼ã«ã¹ããå ¨ä½ã§ã®å¦çé度ã®åä¸ãå³ã£ã¦ãã¾ãã
ä¸ã®è¡¨ã¯ãåå¾æ¸ã¿ã®ã¢ãã«200åã«ã¤ãã¦ãããããã£ã®èªåã¨è¨å®ãåã¢ãã«10åãã¤è¡ã£ãã¨ãã®æéãè¨æ¸¬ãããã®ã§ãã
Transactd | Laravel 5.3 | åç |
---|---|---|
0.0002528 | 0.018078 | 71.5 |
Transactdã¯Laravel 5.3ã®70åãé«éã«ããããã£ã¸ã®èªã¿æ¸ããã§ãã¾ãã
è¤éãªãã¼ã¿ãã¼ã¹å¦ç
ORMã使ãï¼ä½¿ããªãã®å¤æãããéã«ãè¤éãªå¦çã«ãªãã¨ORMã ãã§ãã¼ã¿ãã¼ã¹ã¢ã¯ã»ã¹ãå®çµãã«ããã¨ããåé¡ãããã¾ããTransactdã¯ORMã¨ãã¤ãã£ãAPIã®å¢ç®ãããã¾ãããORMãçãããªããèªç¶ã«ãã¤ãã£ãAPIãå©ç¨ããè¤éãªå¦çã«ã対å¿ã§ãã¾ãã
ã¾ã¨ã
Transactd PHP ORMã¯ãé«éã¬ã¹ãã³ã¹ãçã¡ã¢ãªãé«ã¹ã«ã¼ãããã§ããã·ã§ã³ã¯ãªãã£ã«ã«ãªéçºã«é©ããORMã§ãã
以ä¸ã®ãããªORMãæ¢ãã¦ããæ¹ã«æé©ã§ãã
- MySQLã¸ã®ã¢ã¯ã»ã¹ã®ããWebãã¼ã¸ã®ã¬ã¹ãã³ã¹ãè¯ãããã
- MySQLã¸ã®ã¢ã¯ã»ã¹ã®ããWebãµã¤ãã®ã¹ã«ã¼ããããè¯ããããï¼åç´ã¹ã±ã¼ã«ã¢ãããããï¼
- MySQLã¢ã¯ã»ã¹ããã¹ã¿ã¼ã¨ã¹ã¬ã¼ãã«ç°¡åã«åæ£ããã
- ç¾å¨ä½¿ç¨ãã¦ããORMã§ã¬ã³ã¼ãã®ããã¯ãæä»å¶å¾¡ã«ä¸å®ããã
- ã¢ãã«ã®ããããã£ã¸ã®ã¢ã¯ã»ã¹ãé ãã¨æãã¦ãã
Transactdã¯ãããã·ã§ã³ã¯ãªãã£ã«ã«ã§é«éãªã¬ã¹ãã³ã¹ã¨é«ãã¹ã«ã¼ããããæ±ããã¢ããªã±ã¼ã·ã§ã³ã«æé©ã§ããå°ããªè¦æ¨¡ãã大ããªãã®ã¾ã§å¯¾å¿ã§ãã¾ãã
ORMã®ã¤ã³ã¿ãã§ã¼ã¹ã¯Laravel 5ã«è¿ãã®ã§ãåãããããå¦ç¿ã³ã¹ããå°ãªãã¦ãã¿ã¾ãã
ã¤ã³ã¹ãã¼ã«ã¯Composerã§ç°¡åã«è¡ãã¾ããPackagist transactd/ormãã覧ãã ããã
æ¯éããµã¯ãµã¯ã§å ç¢ãªTransactd PHP ORMãä½æãã¦ã¿ã¦ãã ããã