»ùÓÚSwoole¹¹½¨È«ÉúÃüÖÜÆÚMySQLÊðÀíЧÀ͵Äʵ¼ùÂÄÀú
ÔÚµ±½ñµÄ»¥ÁªÍøʱ´ú£¬mysqlÊý¾Ý¿â×÷ΪһÖÖ¾µäµÄ¹ØϵÐÍÊý¾Ý¿â£¬»ñµÃÁËÆÕ±éµÄÓ¦Ó᣿ÉÊÇ£¬Ðí¶à´óÐÍ»¥ÁªÍøÓ¦ÓóÌÐòÍùÍùÅöÃæÁÙÇå¾²ÐÔ¡¢¸ß¿ÉÓÃÐÔ¡¢ÐÔÄÜÒÔ¼°ÔËάµÄÎÊÌ⡣ΪÏàʶ¾öÕâЩÎÊÌ⣬ÖîÈçÊý¾Ý¿âÊðÀíµÈÖÐÐļþÊÖÒÕ¾ÍÓ¦Ô˶øÉú¡£±¾ÎĽ«ÏÈÈÝÔõÑù»ùÓÚswoole¹¹½¨È«ÉúÃüÖÜÆÚmysqlÊðÀíЧÀ͵Äʵ¼ùÂÄÀú¼°ÓÅÊÆ¡£
Ò»¡¢ SwooleÏÈÈÝ
SwooleÊÇÒ»ÖÖ¸ßÐÔÄÜ¡¢Òì²½¡¢²¢ÐС¢Ð³ÌµÄPHPÍøÂçͨѶÒýÇæ¡£ËüÒÔEventLoopΪ»ù´¡£¬ÌṩTCP¡¢UDP¡¢UnixSocketµÈÀàÐ͵Äг̸ßÐÔÄÜÍøÂçͨѶÄÜÁ¦£¬²¢ÇÒ¼¯³ÉÁËÒì²½MySQL¡¢Redis¡¢HTTPºÍWebSocketµÈЧÀÍ£¬Ê¹µÃ¿ª·¢Õß¿ÉÒÔÇáËɹ¹½¨¸ßÐÔÄÜ¡¢µÍÑÓ³Ù¡¢ÂþÑÜʽµÄÓ¦ÓóÌÐò¡£
Ïà½ÏÓڹŰåµÄPHPÓ¦Óã¬SwooleÒýÇæÖÐг̺ÍÒì²½ÄÜÁ¦µÄ×éºÏÄܹ»ÓÐÓõØÌáÉýÐÔÄÜ£¬³ÉΪÏÖÔÚPHPÓ¦Óõĸ߿ÉÓÃÄѵ㴦Àí¼Æ»®£¬Ê¹ÓÃSwoole¿ÉÒÔÇáËÉÓÅ»¯MySQLÊðÀíЧÀÍ¡£
¶þ¡¢ MySQLÊðÀíЧÀ͵ÄÉè¼Æ
MySQLÊðÀíЧÀÍÐèҪ˼Á¿µ½¸÷¸ö×é¼þµÄÉè¼Æ£¬ÈçÒÔϼ¸¸ö×é¼þ£º
ÅþÁ¬³Ø
MySQL¿Í»§¶ËÐèÒªÓëЧÀÍÆ÷½¨ÉèÅþÁ¬£¬²¢Ö´ÐÐSQLÓï¾ä¾ÙÐÐÊý¾Ý½»Á÷¡£ÎªÁËÓÅ»¯ÐÔÄÜ£¬ÅþÁ¬³ØµÄÉè¼ÆºÜÊÇÖ÷Òª¡£ÅþÁ¬³Ø¿ÉÒÔ»º´æÒѾ½¨ÉèµÄÅþÁ¬£¬ÒÔ×èֹÿ´Î¶¼ÖØн¨ÉèÅþÁ¬£¬´Ó¶øÌá¸ßЧÀÍÐÔÄÜ¡£
Êý¾Ý»º´æ
ÔÚMySQLÊðÀíЧÀÍÖУ¬Êý¾Ý»º´æÆð×ÅÖ÷ÒªµÄ×÷Óá£ÎªÁË×èֹÿ´ÎÇëÇó¶¼ÐèÒª»á¼ûÊý¾Ý¿âµÄIO²Ù×÷£¬ÊðÀíЧÀÍÓ¦¸ÃÔÚÄÚ´æÖлº´æÊý¾Ý¡£ÕâÑù¿ÉÒÔÓÐÓõĽµµÍÊý¾Ý¿âµÄ²¢·¢»á¼ûÊý£¬Í¬Ê±¿ÉÒÔÌá¸ßЧÀÍÐÔÄÜ¡£
ÊðÀíÕ½ÂÔ
ÊðÀíÕ½ÂÔÊÇÖ¸MySQLÊðÀíЧÀÍÔÚ²î±ðÇéÐÎÏÂÓ¦¸ÃÈçÄÇÀïÖÿͻ§¶ËÇëÇóµÄÒ»×é¹æÔò¡£ÔÚʵ¼ùÖУ¬ÊðÀíÕ½ÂÔ¿ÉÒÔͨ¹ý¶à¸öά¶È¾ÙÐзÖÀàºÍÖÎÀí£¬Èç°´SQLÀàÐÍ·ÖÀà¡¢°´Óû§·ÖÀࡢ׼ʱ¼ä·ÖÀàµÈ¡£Í¨¹ýÖƶ©²î±ðµÄÕ½ÂÔ¹æÔò£¬¿ÉÒÔÌá¸ßϵͳµÄÎȹÌÐÔºÍÇå¾²ÐÔ¡£
Òì³£´¦Àí
Êý¾Ý¿âÒì³£´¦ÀíºÜÊÇÖ÷Òª¡£ÔÚÓ¦ÓóÌÐò¿ª·¢Àú³ÌÖУ¬¾³£»á·ºÆðÊý¾Ý»á¼ûÒì³£µÄÇéÐΡ£MySQLÊðÀíЧÀÍÐèÒª¾ß±¸Ò»¶¨µÄ´¦ÀíÒì³£µÄÄÜÁ¦£¬ÀýÈ磬±¬·¢Ò쳣ʱӦ¸ÃÔõÑùÖØÊÔ£¬Ó¦¸ÃÔõÑù»Ø¹öÊÂÎñµÈ¡£
Èý¡¢ »ùÓÚSwoole¹¹½¨MySQLÊðÀíЧÀÍ
»ùÓÚSwoole¹¹½¨MySQLÊðÀíЧÀÍÐèÒªÖصã˼Á¿ÒÔϼ¸¸ö·½Ã棺
ÅþÁ¬³ØµÄʵÏÖ
ÔÚSwooleÒýÇæÖУ¬¿ÉÒÔʹÓÃSwooleCoroutineMySQLʵÏÖMySQL¿Í»§¶ËÅþÁ¬³Ø£¬Í¨¹ý¶Ôг̵ÄʹÓ㬿ÉÒÔʵÏÖMySQLµÄ¸ß²¢·¢´¦Àí¡£
Êý¾Ý»º´æµÄʵÏÖ
ÔÚSwooleÖУ¬¿ÉÒÔʹÓÃЧÀ͵ÄÄڴ滺´æ½â¾öÊý¾Ý»º´æµÄÎÊÌâ¡£ÀýÈ磬¿ÉÒÔʹÓÃSwooleµÄTableÀàÀ´ÊµÏÖ£¬½«MySQLÖеÄÊý¾Ý»º´æµ½ÄÚ´æÖУ¬´Ó¶ø×èֹÿ´ÎÇëÇó¶¼ÐèÒª»á¼ûÊý¾Ý¿âµÄIO²Ù×÷¡£
ÊðÀíÕ½ÂÔµÄʵÏÖ
SwooleµÄEventLoop»úÖÆ¿ÉÒÔ´¦Àí´ó×ڵIJ¢·¢ÅþÁ¬ÇëÇ󣬲¢ÇÒSwoole¿ÉÒÔʹÓÃSwoole Atomic¡¢Swoole Lock¡¢Swoole Coroutine¡¢Swoole TimerµÈ¹¦Ð§À´ÊµÏÖÊðÀíÕ½ÂÔ¡£ÀýÈ磬¿ÉÒÔͨ¹ýSwoole TimerÀ´×¼Ê±É¨³ý»º´æÊý¾Ý£¬´Ó¶øÓÅ»¯MySQLÊðÀíЧÀ͵ÄÐÔÄÜ¡£
Òì³£´¦ÀíµÄʵÏÖ
ÔÚMySQLÊðÀíЧÀ͵ÄʵÏÖÖУ¬ÐèҪ˼Á¿Òì³£´¦Àí¡£ÀýÈ磬µ±MySQLÖ´ÐÐÒ쳣ʱ£¬Ó¦¸ÃÈçÄÇÀïÖá£ÔÚSwooleÖУ¬¿ÉÒÔʹÓÃSwooleTable»òSwooleAtomicÀ´ÊµÏÖÒì³£´¦Àí£¬ÀýÈ磬ÔÚ±¬·¢Òì³£µÄÇéÐÎÏ£¬¿ÉÒÔʹÓÃSwooleAtomicÀ´¾ÙÐмÆÊýÆ÷´¦Àí£¬´Ó¶øÔÚºóÐøµÄÇëÇóÖÐ×èÖ¹Ó°Ï쵽ϵͳµÄÎȹÌÐÔ¡£
ËÄ¡¢ ÓÅÊÆ
»ùÓÚSwoole¹¹½¨MySQLÊðÀíЧÀÍ£¬¾ßÓÐÒÔÏÂÓÅÊÆ£º
¸ßÐÔÄÜ
Swoole¿ò¼Ü¿ÉÒÔгÌʽµØÖ§³ÖMySQLÊðÀíЧÀÍ£¬Äܹ»ÓÐÓÃÌá¸ßЧÀ͵ÄÐÔÄܺͲ¢·¢´¦ÀíÄÜÁ¦£¬´Ó¶øΪ»¥ÁªÍø´óÐÍÓ¦ÓóÌÐòÌṩÁ˸üºÃµÄÖ§³Ö¡£
¸ß¿ÉÓÃÐÔ
ͨ¹ýSwoole¶ÔMySQLÊðÀíЧÀ͵ÄÓÅ»¯£¬¿ÉÒÔ´ó´óÌá¸ßÊý¾Ý¿â»á¼ûµÄ¿ÉÓÃÐÔºÍÎȹÌÐÔ£¬ïÔÌÊý¾Ý¿â¸ºÔØ£¬½µµÍ¹ÊÕÏÂÊ¡£
Çå¾²ÐÔ
Õë¶ÔSQL×¢Èë¡¢ºÚ¿Í¹¥»÷µÈÇå¾²ÎÊÌ⣬Swoole¿ÉÒÔͨ¹ýÊðÀíÕ½ÂÔ¡¢Òì³£´¦Àí»úÖƵȶàÖØ°ü¹Ü²½·¥À´°ü¹ÜϵͳµÄÇå¾²ÐÔ¡£
Îå¡¢ ×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑù»ùÓÚSwoole¹¹½¨È«ÉúÃüÖÜÆÚMySQLÊðÀíЧÀ͵Äʵ¼ùÂÄÀú¼°ÓÅÊÆ¡£ÔÚÏÖ´ú»¥ÁªÍøÓ¦ÓóÌÐòµÄ¿ª·¢ÖУ¬MySQLÊðÀíЧÀ;ßÓÐÔ½À´Ô½Ö÷ÒªµÄְ룬¹ØÓÚÌá¸ßÓ¦ÓóÌÐòµÄÔËÐÐЧÂÊ¡¢ÎȹÌÐÔºÍÇå¾²ÐÔ¶¼ÓÐ×ÅÖ÷ÒªµÄ×÷Óá£Swoole×÷ΪһÖÖÐÔÄÜÓÅÒìµÄPHPÍøÂçͨѶÒýÇ棬Äܹ»ÓÐÓõÄÌá¸ßMySQLÊðÀíЧÀ͵ÄÐÔÄÜ¡¢¿ÉÓÃÐÔºÍÇå¾²ÐÔ£¬Îª»¥ÁªÍø´óÐÍÓ¦ÓóÌÐòÌṩÁ˸üºÃµÄÖ§³Ö¡£
ÒÔÉϾÍÊÇ»ùÓÚSwoole¹¹½¨È«ÉúÃüÖÜÆÚMySQLÊðÀíЧÀ͵Äʵ¼ùÂÄÀúµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡