laravelÐÐÁм¸¶àÀú³Ì
laravelÐÐÁм¸¶àÀú³Ì
LaravelÐÐÁÐÊÇÒ»¸öºÜÊÇÇ¿Ê¢µÄ¹¦Ð§£¬¿ÉÒÔÈÃÄãÔËÐÐһЩʹÃü£¬ºÃ±È·¢Ë͵ç×ÓÓʼþ¡¢ÌìÉú±¨¸æ»òµ¼ÈëÊý¾Ý£¬¶ø²»±Øµ£ÐÄ»áÓ°Ïìµ½Ó¦ÓõÄÐÔÄÜ¡£¿ÉÊÇ£¬µ±Óжà¸öʹÃüÐèҪͬʱÔËÐÐʱ£¬Äã¾ÍÐèҪ˼Á¿ÔõÑù×î´óÏ޶ȵØʹÓÃЧÀÍÆ÷×ÊÔ´¡£ÐÐÁÐÀú³ÌµÄÊýÄ¿ÊÇÒ»¸öºÜÊÇÖ÷ÒªµÄ¾öÒ飬ÓÉÓÚËü»áÓ°Ïìµ½ÐÐÁеÄÐÔÄܺÍÎȹÌÐÔ¡£
ÔÚÕâƪÎÄÕÂÖУ¬ÎÒÃǽ«ÌÖÂÛLaravelÐÐÁÐÓ¦¸ÃʹÓü¸¶à¸öÀú³ÌÀ´Ö´ÐÐʹÃü¡£ÎÒÃǽ«Ë¼Á¿Õâ¸öÎÊÌâµÄ²î±ð·½Ã棬²¢¸ø³öһЩÊÊÓõĽ¨Ò飬ÒÔ×ÊÖúÄãΪÄãµÄÓ¦ÓóÌÐòÑ¡ÔñÒ»¸öºÏÊʵÄÐÐÁÐÀú³ÌÊý¡£
ʲôÊÇLaravelÐÐÁУ¿
LaravelÐÐÁÐÊÇÒ»¸öÈÃÄãÔÚºǫ́ÔËÐÐí§Òⳤʱ¼äµÄʹÃüµÄ½â¾ö¼Æ»®¡£Ê¹Ãü¿ÉÒÔ±»Òì²½Ö´ÐУ¬ÕâÒâζ×ÅËüÃÇ»áÔÚºǫ́ÔËÐУ¬²»»áÓ°Ïìµ½Ó¦ÓóÌÐòµÄÐÔÄÜ¡£µ±ÐèÒªÖ´ÐÐij¸öʹÃüʱ£¬Laravel»á½«Õâ¸öʹÃüÍÆÈëÐÐÁÐÖУ¬È»ºóÈúǫ́Àú³Ì»òÕßʹÃüµ÷Àí³ÌÐòÈ¥Òì²½Ö´ÐÐÕâ¸öʹÃü¡£
LaravelÄÚÖÃÖ§³Ö¶à¸öÐÐÁÐÇý¶¯³ÌÐò£¬°üÀ¨Beanstalkd¡¢Redis¡¢Amazon SQS¡¢Í¬²½£¨sync£©µÈ¡£ÕâЩÇý¶¯³ÌÐòÌṩÁËÒ»ÖÖÇ¿Ê¢µÄ·½·¨À´ÖÎÀíÐÐÁУ¬²¢ÄÜÈÃÄãͨ¹ý¶à¸öÀú³Ì»òЧÀÍÆ÷À´´¦ÀíÐÐÁÐÖеÄʹÃü¡£Äã¿ÉÒÔͨ¹ýLaravelµÄÏÂÁîÐй¤¾ßartisanÀ´Æô¶¯Ò»¸öÐÐÁÐÀú³Ì£¬À´Ö´ÐÐÐÐÁÐÖеÄʹÃü¡£
ΪʲôҪʹÓöà¸öÀú³Ì£¿
µ±ÄãÓжà¸öʹÃüÐèÒªÖ´ÐÐʱ£¬Äã¿ÉÄÜ»áÏëÖªµÀÓ¦¸ÃʹÓü¸¶à¸öÀú³ÌÀ´´¦ÀíÐÐÁС£Õâ¸öÎÊÌâµÄÃÕµ×È¡¾öÓÚÄãµÄÓ¦ÓóÌÐòµÄÌض¨ÐèÇóºÍÏÞÖÆ¡£
ÈôÊÇÄãÖ»ÓÐÒ»¸öÐÐÁÐÀú³ÌÔÚ´¦ÀíÄãµÄÐÐÁÐʹÃü£¬ÄÇôµ±ÄãÓжà¸öʹÃüʱ£¬Õâ¸öÀú³Ì¿ÉÄÜ»á±äµÃºÜÊÇæµ£¬²¢ÇÒ¿ÉÄܻᵼÖÂÐÔÄÜϽµ¡£ÕâÖÖÇéÐÎÏ£¬Äã¿ÉÄÜÐèÒªÔöÌíÐÐÁÐÀú³ÌÊý£¬ÒÔ±ãÄܹ»Í¬Ê±´¦Àí¶à¸öʹÃü¡£
ÁíÒ»·½Ã棬ÈôÊÇÄãʹÓÃÌ«¶àµÄÐÐÁÐÀú³Ì£¬Äã¿ÉÄÜ»áÆÌÕÅЧÀÍÆ÷×ÊÔ´£¬²¢ÇÒÔöÌíϵͳÉÏÏÂÎÄÇл»µÄ±¾Ç®¡£ÈôÊÇÄãÓжà¸öÀú³ÌÔÚ»á¼ûÏàͬµÄÊý¾Ý¿â£¬²¢ÇÒÿ¸öÀú³Ì¶¼ÔÚʵÑéÖ´ÐÐÏàͬµÄʹÃü£¬ÄÇôÄã¿ÉÄܻᷢÃ÷ÕâЩÀú³ÌÔÚÏ໥֮¼ä±¬·¢²»ÐëÒªµÄ¾ºÕù£¬µ¼ÖÂϵͳ±äÂý»òÕßÍ߽⡣
×ÛÉÏËùÊö£¬ÄãÐèҪƾ֤ÄãµÄÓ¦ÓóÌÐòµÄÐèÇóºÍÏÞÖÆ£¬Ñ¡ÔñÒ»¸öºÏÊʵÄÐÐÁÐÀú³ÌÊýÀ´´¦ÀíÐÐÁÐʹÃü¡£
ÔõÑùÑ¡ÔñÐÐÁÐÀú³ÌÊý£¿
LaravelÌṩÁËÒ»¸öºÜÊǼòÆӵķ½·¨À´Ñ¡ÔñÐÐÁÐÀú³ÌÊýÄ¿£¬Í¨¹ýʹÓÃartisanÏÂÁîÐй¤¾ßµÄ–concurrencyÑ¡Ïî¡£Õâ¸öÑ¡ÏîÔÊÐíÄãÖ¸¶¨Í¬Ê±ÔËÐеÄÐÐÁÐÀú³ÌÊý¡£ÀýÈ磬ÈôÊÇÄãÏëͬʱÔËÐÐ4¸öÐÐÁÐÀú³Ì£¬Äã¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
php artisan queue:work --concurrency=4
µÇ¼ºó¸´ÖÆ
Äã¿ÉÒÔƾ֤ÐèÒªÔöÌí»òïÔÌ´ËÊýÄ¿¡£
µ±ÄãÑ¡ÔñÐÐÁÐÀú³ÌÊýʱ£¬ÄãÐèҪ˼Á¿ÒÔϼ¸¸öÒòËØ£º
1.ЧÀÍÆ÷Ó²¼þ×ÊÔ´
Ò»¸öЧÀÍÆ÷µÄÄÜÁ¦ÊÇÓÐÏ޵ģ¬ÈôÊÇÄãÔÚͳһ̨ЧÀÍÆ÷ÉÏÔËÐжà¸öÀú³Ì£¬ÄÇôÄãÐèҪ˼Á¿Ð§ÀÍÆ÷Ó²¼þ×ÊÔ´µÄÏÞÖÆ¡£ÈôÊÇÄãÔÚͳһ̨ЧÀÍÆ÷ÉÏÔËÐÐÌ«¶àÀú³Ì£¬ÄÇôÄã¿ÉÄÜ»áÓöµ½ÄÚ´æȱ·¦¡¢CPU¹ýÔصÈÎÊÌ⣬´Ó¶øµ¼ÖÂϵͳ±ÀÀ£»ò±äÂý¡£
2.ÐÐÁÐʹÃüµÄÀàÐÍ
²î±ðÀàÐ͵ÄʹÃüÐèÒª²î±ðµÄ´¦Àí·½·¨¡£ÓÐЩʹÃü¿ÉÄÜÐèÒª¸ü¶àµÄÄÚ´æ»òCPU×ÊÔ´£¬¶øÓÐЩʹÃü¿ÉÄÜÐèÒª´ó×ڵĴÅÅÌIO¡£µ±ÄãÑ¡ÔñÐÐÁÐÀú³ÌÊýʱ£¬ÄãÐèҪ˼Á¿µ½ÐÐÁÐʹÃüµÄÌص㣬ÒÔ°ü¹Üÿ¸öʹÃü¶¼Äܱ»ÊµÊ±´¦Àí¡£
3.ÐÐÁÐʹÃüµÄÊýÄ¿
ÄãÔÚÐÐÁÐÖÐÅŶӵÄʹÃüÊýÄ¿¶ÔÐÐÁÐÀú³ÌÊýµÄÑ¡ÔñÒ²ÓÐÓ°Ïì¡£ÈôÊÇÄãµÄÐÐÁÐÖÐÖ»Óм¸Ê®¸öʹÃüÐèÒª´¦Àí£¬ÄÇôʹÓÃÒ»¸ö´¦ÀíÀú³ÌÊÇÍêÈ«¹»Óõġ£µ«ÈôÊÇÄãµÄÐÐÁÐÖÐÓÐÊý°Ù¸ö»òÊýǧ¸öʹÃüÐèÒªÅŶÓʱ£¬Äã¿ÉÄÜÐèÒª¶à¸öÀú³ÌÀ´²¢Ðд¦ÀíÕâЩʹÃü¡£
×ÜÖ®£¬Ñ¡ÔñÐÐÁÐÀú³ÌÊýĿʱ£¬ÐèҪȨºâЧÀÍÆ÷Ó²¼þ×ÊÔ´¡¢ÐÐÁÐʹÃüÌصãºÍÐÐÁÐÖÐʹÃüÊýÄ¿µÈÒòËØ¡£
×î¼Ñʵ¼ù
ÔÚÏÖʵÖУ¬ÎÒÃÇ¿ÉÒÔƾ֤ÏÂÁÐÂÄÀú¹æÔòÀ´ÉèÖÃÐÐÁÐÀú³ÌÊý£º
1.½«ÐÐÁÐÀú³ÌÊýÉèÖÃΪЧÀÍÆ÷CPU½¹µãÊýµÄÒ»°ë¡£ÕâÑù¿ÉÒÔÈ·±£Ð§ÀÍÆ÷CPU×ÊÔ´»ñµÃ³ä·ÖʹÓ㬲¢ÇÒ¿ÉÒÔÔÚͳһʱ¼ä´¦Àí¶à¸öʹÃü¡£
2.ÈôÊÇÄãµÄЧÀÍÆ÷ÉÏÓÐÆäËûʹÃü»òЧÀÍÕýÔÚÔËÐУ¬ÄÇôÇ뽫ÐÐÁÐÀú³ÌÊýÄ¿½µµ½½ÏµÍµÄˮƽ¡£ÕâÑù¿ÉÒÔ×èÖ¹¹ý¶àµÄ¾ºÕùÌõ¼þºÍϵͳ¸ºÔØ¡£
3.ƾ֤ijЩʹÃüµÄÌØÕ÷ÉèÖÃÐÐÁÐÀú³ÌÊý¡£ÀýÈ磬ÈôÊÇÄãµÄÐÐÁÐʹÃüÉæ¼°´ó×ڵĴÅÅÌI/O£¬ÄÇôÄã¿ÉÄÜÐèҪѡÔñ½ÏµÍµÄÐÐÁÐÀú³ÌÊý£¬ÒÔ×èÖ¹¹ý¶àµÄ´ÅÅ̾ºÕù¡£
4.ÔÚÉú²úÇéÐÎÖУ¬ÇëʹÓöà¸öЧÀÍÆ÷À´´¦ÀíÐÐÁÐʹÃü£¬²¢½«ÐÐÁÐÀú³ÌÊý·ÖÅɵ½²î±ðµÄЧÀÍÆ÷ÉÏ¡£ÕâÑù¿ÉÒÔÌá¸ßϵͳµÄ¿ÉÉìËõÐԺͳ°ôÐÔ¡£
×ܽá
ÔÚÑ¡ÔñLaravelÐÐÁÐÀú³ÌÊýĿʱ£¬ÐèҪ˼Á¿µ½Ð§ÀÍÆ÷Ó²¼þ×ÊÔ´¡¢ÐÐÁÐʹÃüÌصãºÍÐÐÁÐÖÐʹÃüÊýÄ¿µÈÒòËØ¡£ÎªÁË»ñµÃ×î¼ÑÐÔÄܺÍÎȹÌÐÔ£¬Äã¿ÉÄÜÐèҪʵÑé²î±ðµÄÐÐÁÐÀú³ÌÊý£¬²¢×îÖÕÑ¡ÔñÒ»¸ö×îÊʺÏÄãµÄÓ¦ÓóÌÐòµÄÊýÄ¿¡£
×îºó£¬Ò»¶¨ÒªÔÚÉú²úÇéÐÎÖвâÊÔÄãµÄÐÐÁÐÉèÖã¬ÒÔÈ·±£Ëü¿ÉÒÔ´¦ÀíÈκÎÊýÄ¿µÄʹÃü£¬²¢ÇÒ²»»áÓ°Ïìµ½Ó¦ÓóÌÐòµÄÐÔÄÜ»òÎȹÌÐÔ¡£
ÒÔÉϾÍÊÇlaravelÐÐÁм¸¶àÀú³ÌµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡