ç§ã®èšäºã®1 ã€ã§ãPythonã§Tarantoolã䜿çšããéåæäœæ¥ã«ã€ããŠèª¬æããŸãã ã ãã®èšäºã§ã¯ãã®ãããã¯ãç¶ããŸããã Tarantoolã®ãã¥ãŒãä»ããæ å ±ã®åŠçã«æ³šæãæããããšæããŸãã ç§ã®ååã¯ããã¥ãŒã®å©ç¹ã«é¢ããããã€ãã®èšäºãå ¬éããŠããŸãïŒ äŸãšããŠã My WorldãœãŒã·ã£ã«ãããã¯ãŒã¯ã§ã®åŠçã€ã³ãã©ã¹ãã©ã¯ãã£ã®ãã¥ãŒã€ã³ã°ãšãREST APIã§ã®ããã·ã¥éç¥ ïŒã Pythonãšasyncioã§Tarantool Queueãæäœããããšãšåæ§ã«ãåé¡ã®è§£æ±ºçã®äŸã«ãã£ãŠãã¥ãŒã«é¢ããæ å ±ãè£è¶³ããããšæããŸãã RedisãRabbitMQã§ã¯ãªããTarantoolãéžæããçç±ã¯äœã§ããïŒ
ããŠãŒã¶ãŒããŒã¹å šäœã«ãã¡ãã»ãŒãžãéä¿¡ããã¿ã¹ã¯
Mail.Ruã«ã¯å€ãã®ã¡ãã£ã¢ãµã€ãããããŸãïŒ News ã Auto ã Lady ã Health ã Hi-Techãªã©ãæ¯æ¥äœçŸäžäººãã®ãŠãŒã¶ãŒããããã蚪ããŸãã ãµã€ãã¯ã¢ãã€ã«ããã€ã¹ã«é©åããŠããããããã®ã»ãšãã©ã«ã¯ã¿ããããŒãžã§ã³ããããŸãã ãŠãŒã¶ãŒã®å©äŸ¿æ§ã®ããã«ãAndroidããã³iOSããã€ã¹ã§äººæ°ã®ããNewsã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ãäœæããŸããã ããããããã¥ãŒã¹ã®å ¬éåŸãã¢ããªã±ãŒã·ã§ã³ã®åãŠãŒã¶ãŒã¯ããã·ã¥éç¥ãåãåããŸãã éåžžã次ã®ããã«è¡šç€ºãããŸããç·šéé·ããã¥ãŒã¹ãéžæãã管çããã«ã®[ç«çœ]ãã¿ã³ãã¯ãªãã¯ãããšãããã ãã§ãïŒ ããããäœïŒ 次ã«ããã®ãã¥ãŒã¹ãã§ããã ãæ©ããµãã¹ã¯ã©ã€ããŒããŒã¿ããŒã¹å šäœã«éä¿¡ããå¿ èŠããããŸãã 誰ãã30å以å ã«ããã·ã¥éç¥ãåä¿¡ããå Žåããããããã¥ãŒã¹ã¯ããã»ã©ãããããã§ã¯ãªãããŠãŒã¶ãŒã¯å¥ã®ãœãŒã¹ããããã«ã€ããŠåŠç¿ããŸãã ããã¯ç§ãã¡ã®å Žåã§ã¯ãããŸããã
ã ãããç§ãã¡ã®ææã®ã¿ã©ã³ããŒã«ã«ä¿åãããŠããããŒã¿ããŒã¹ããããŸãã ããŒã¿ããŒã¹å šäœãã§ããã ãæ©ãåé¿ãããã¹ãŠã®ãµãã¹ã¯ã©ã€ããŒã«ããã·ã¥éç¥ãéä¿¡ããå¿ èŠããããŸãã ããããã«ã€ããŠãããã·ã¥ããŒã¯ã³ãšjson圢åŒã®ããã€ã¹ã«é¢ããããã€ãã®æ å ±ãããŒã¿ããŒã¹ã«ä¿åãããŸããã¢ããªã±ãŒã·ã§ã³ããŒãžã§ã³ãç»é¢è§£å床ãã¿ã€ã ãŸãŒã³ããŠãŒã¶ãŒãéç¥ãåä¿¡ããæéééã§ãã ã¿ã€ã ãŸãŒã³ãæå®ããããšã¯éåžžã«éèŠã§ãã誰ããç ã£ãŠããå€éã«ããã·ã¥éç¥ãéä¿¡ããããšã¯ãå§ãã§ããŸããã
èŠä»¶ãããã°ããã¹ãŠãæ確ã«ãªããŸãã
åé¡ã解決ããŸã
éåžžãé¡ã®åé¡ãç°¡åãªæ¹æ³ã§è§£æ±ºãå§ããŸãã åçŽãªã³ãŒãã¯åžžã«éåžžã«ãããã«èŠããŸãã
while « »: «» - «»
ã¡ã€ã³ã®
while
ã¯ããã¹ãŠã®ãŠãŒã¶ãŒãåŠçãããŸã§å®è¡ãããŸãã ãŠãŒã¶ãŒããŒã¹ãå°ããå Žåããã以äžäœãããããšãã§ãããåé¡ã¯è§£æ±ºããŸãã ããã§äœãæ¹åã§ããŸããïŒ ãã®ãããªãµã€ã¯ã«ãã¹ããŒãã¢ããããæ¹æ³ã¯ïŒ ããŒã¿ããŒã¹ã®ãµã€ãºã«é¢ä¿ãªããäžå®æééä¿¡ããæ¹æ³ã¯ïŒ ãããè¡ãã«ã¯ãéç¥ãéä¿¡ããããã»ã¹ã®è©³çŽ°ãæ確ã«ããå¿ èŠããããŸãã
ç°¡åã«ããããã«ã2ã€ã®Androidãã©ãããã©ãŒã ãšiOSãã©ãããã©ãŒã ã«çŠç¹ãåœãŠãŸãã ãããã·ã¥éä¿¡ããšã¯äœã§ããïŒ ã©ããã£ãŠããã®ïŒ Google Cloud Messagingããã³Apple Push Notification Serviceãããã³ã«ã®èª¬æããããŸãã Pythonã®Androidããã³iOSã§ããã·ã¥éç¥ãéä¿¡ããããã®æ¢è£œã®ã©ã€ãã©ãªããããéåžžã®ãåæãã¢ãŒãã§åäœããããã«èšèšãããŠããŸãã ããã«æ·±ãæãäžãããšãåãã©ãããã©ãŒã ã«ã¯åºæã®ç¹æ§ããããŸãã Androidã§ã®ããã·ã¥ãšã¯ãhttpsãä»ããŠjsonããŒã¿ãéä¿¡ããããšãæå³ããiOSã§ã¯ãsslãœã±ããã«ãã€ããªããŒã¿ãéä¿¡ããŸãã Appleã¯éããªãHTTP / 2ãããã³ã«ã®ãµããŒããçŽæããŸãã Androidã§ã¯ãè€æ°ã®å®å ãžã®éä¿¡ãå¯èœã§ãã IOSã«ã¯ãè€æ°ã®ãŠãŒã¶ãŒãã°ã«ãŒãåããã°ã«ãŒãã«éç¥ãéä¿¡ããæ©èœããããŸãã ã€ãŸããåãã©ãããã©ãŒã ã®ã°ã«ãŒãåã«ãç¬èªã®ç¹æ§ããããŸãã
ãã¥ãŒã®æ±ºå®ã¯æããã«é Œãã«ãªããŸãã ããŒã¿ããŒã¹ãããŠãŒã¶ãŒãéžæããããã»ã¹ãšããã©ãããã©ãŒã ããšã«éç¥ãéä¿¡ããããã»ã¹ãåé¢ããããšæããŸãã ããããå€ãã®éèŠãªè©³çŽ°ããããŸãã ãããã©ãããã©ãŒã ãå¥ã®ãã©ãããã©ãŒã ããéä¿¡ããããã»ã¹ãç¬ç«ãããããã«ãiOSããã³Androidã§éžæããããã³ãã«ããããŠãŒã¶ãŒãåé¢ãããŠãŒã¶ãŒãã°ã«ãŒãåããç®çã®ãã¥ãŒã«éä¿¡ããã¡ãã»ãŒãžãè¿œå ã§ããŸãã ããã«ã¡ãã»ãŒãžãåŠçã§ããŸããã€ãŸããããã·ã¥éç¥ãéä¿¡ããäœæ¥ãçŽæ¥å®è¡ã§ããŸãã æŠç¥çã«ããããã®ããã»ã¹ã¯ãã¹ãŠæ¬¡ã®ããã«è¡šãããšãã§ããŸãã
ãŠãŒã¶ãŒããŒã¹ããã€ãã¹ãããã¥ãŒãä»ããŠã¡ãã»ãŒãžãåŠçããã¹ããŒã
ãã®ãããªã¢ãããŒãã¯äœãããããã§ããããïŒ ãŠãŒã¶ãŒããŒã¹ããã€ãã¹ããããã»ã¹ãããã·ã¥éç¥ããåé¢ããŸãã ãããã£ãŠãå ã®ã«ãŒãã®ããã³ãã«ããããé«éã«ãœãŒãïŒ
select_range
å®è¡ïŒã
select_range
ãŸãã ãã©ãããã©ãŒã ã®1ã€ã§ã¡ãã»ãŒãžãåŠçããéã«æœåšçãªåé¡ãçºçããå ŽåïŒãããŠããã®ãããªããšãé »ç¹ã«çºçããå ŽåïŒãããã¯ä»ã®ãã©ãããã©ãŒã ã§ã®é åžã«ã¯åœ±é¿ããŸããã ãããã£ãŠãè«çãã¥ãŒãããããããµãŒããŒã³ã¢éã§ã¡ãã»ãŒãžåŠçãç°¡åã«äžŠååã§ããŸãã ã·ã¹ãã ãå°ãæ¡åŒµããå¿ èŠãããå Žåã¯ãæ°ããè«çãã¥ãŒãè¿œå ããã ãã§ãã
ããŒããšã¹ã±ãŒãªã³ã°ã®åé¡ã解決ããŸã
1ã€ã®ãµãŒããŒã®è² è·ãå¢å ãããšãCPUã¯ããã«çµäºããŸãã å¥ã®ãµãŒããŒãè¿œå ããŸããïŒ ã¯ãããŸã£ããåãã§ãã ãã ããããã¯ãµãŒãã¹ã®èšèšæ®µéã§è¡ãæ¹ãé©åã§ãã ã·ã¹ãã ã2å°ã®ãµãŒããŒã§åäœãããå Žåãæ°åå°ãè¿œå ããããšã¯é£ãããããŸããã ç§ãã¡ã¯ãã®ååãå®ããŸããå®éã®è² è·ããªãå Žåã§ããå°ãªããšã2å°ã®ãµãŒããŒã§ãã ããã€ãã®ãµãŒããŒã¯ããµãŒãã¹ã®ä¿¡é Œæ§ãé«ããŸãã ãµãŒãã¹ã¢ãŒããã¯ãã£ã®åœ¢åŒã¯æ¬¡ã®ãšããã§ãã
2å°ã®ãµãŒããŒã§ãŠãŒã¶ãŒããŒã¿ããŒã¹ããã€ãã¹ããã¹ããŒã
ãã®ããã2ã€ã®ãµãŒããŒããããããããã«ç¬èªã®ãã¥ãŒããããŸãïŒãã¡ããããŠãŒã¶ãŒããŒã¿ããŒã¹ããããŸããããã¯è¿ãã®ã©ããã«ãããšèãããã
select_range
ã§å©çšã§ããŸãããããã«ã¯ããŸã泚æãæããŸããïŒã 2ã€ã®ãµãŒããŒã§ã¯ããŒã«ã«ãŒãã䞊è¡ããŠéå§ããããšãéåžžã«éèŠã§ãã ããããã®ãµãŒããŒã§ãµã€ã¯ã«ãç¹°ãè¿ãããããã¯ããéžæããåãããã¯ããç°ãªããã¥ãŒã«é 眮ãããããã¯ãããã¹ãŠã®ãµãŒããŒã«åçã«åæ£ããããšãã§ããŸãã ãã®ã¢ãããŒãã§ã¯ããããã¯ãŒã¯ãä»ããŠããŒã¿ããé§åãããå¿ èŠããããŸãã ããã³ãã«ããéžæããŠå¥ã®ãµãŒããŒã®ãã¥ãŒã«å ¥ããããšã¯ããã®ã¢ãããŒãã®åŒ±ç¹ã§ãã ãµãŒããŒéã§
select_range
ã䞊ååããå¿ èŠããããŸãã
ãããè¡ãã«ã¯ãããããã®ãµãŒããŒã§ããã±ããããéžæããçŸåšã®ããã±ããããããé£æ¥ããµãŒããŒã«æåŸã®ãŠãŒã¶ãŒIDã«é¢ããæ å ±ãå«ãå°ããªã¡ãã»ãŒãžãè¿œå ããŸãã 2çªç®ã®ãµãŒããŒã§å°ããªã¡ãã»ãŒãžãåŠçããå Žåãæå®ãããIDã§å§ãŸããæ°ãããã±ããããååŸãããè¿é£ãµãŒããŒããªã©ãšåæ§ã®ã¡ãã»ãŒãžãäœæããŠãããŒã¿ããŒã¹å šäœããœãŒãããå¿ èŠããããŸãã çŸåšã®ããã³ãã«ãã¯ãåžžã«ãã®ãã¥ãŒã§ããŒã«ã«ã«åŠçããå¿ èŠããããŸãã ãããã£ãŠãã³ãŒããããŒã¿ã«ã移åããããµãŒããŒäžã®ããã±ãããã®çæã䞊ååãããããã¯ãŒã¯äžã§ããŒã¿ãé§åããŸããã
ã·ãŒã±ã³ã¹å³ã¯æ¬¡ã®ããã«ãªããŸãã
ããã¹ãŠã®ãŠãŒã¶ãŒåããã«ãŒãã¯ã
queue.put(last_id)
ä»ããŠæé»çã«å®è¡ãããŸãã
select_range
ãŠãŒã¶ãŒã
select_range
ã¡ãŒã«éä¿¡ããã»ã¹ã¯
select_range
ãŸãã åæ£ã¹ããŒã ã§ã¯ãããŒã¿ããŒã¹ã«ããã¯ããªãããšãéåžžã«éèŠã§ãã ãã®ã¹ããŒã ã¯ãHadoopã®MapReduceããã»ã¹ãšéåžžã«ãã䌌ãŠããããåå²ããŠåŸæããããšããåãååã§ãã
å®çšŒåç°å¢ã§ããŸã£ããåãã¢ãŒããã¯ãã£ã䜿çšãããŠããŸãã ã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ãšãã©ãããã©ãŒã ã®ã¿ã€ãããšã«ãåå¥ã®è«çãã¥ãŒã䜿çšãããããã»ã¹ã®ç¬ç«ãã䞊åå®è¡ãå¯èœã«ãªããŸãã 200äžçªç®ã®ãŠãŒã¶ãŒããŒã¹ã§ãã¥ãŒã¹ã®ããã·ã¥éç¥ãéä¿¡ããããã«çŽ2åãéä¿¡ããŸãã ãã®ãããªã¡ãŒãªã³ã°ã«å ããŠã8å°ã®ãµãŒããŒã®ã¯ã©ã¹ã¿ãŒã¯1ç§ãããçŽ1äžä»¶ã®ããã·ã¥éç¥ãéä¿¡ããŸãã
Tarantool Queueã®ã³ãŒãäœæã®æ©èœ
å€æ°ã®è«çãã¥ãŒã䜿çšããæ¹æ³ 1ã€ã®Pythonããã»ã¹ã§ãã¹ãŠã®ãã¥ãŒã®ããŒã¿ãåæã«çæããã³çæããæ¹æ³ éåæããã°ã©ãã³ã°æè¡ãå©ãã«ãªããŸãã äŸã§ã¯ãCentos 6.4ãPython 3ãasyncioã aiotarantool_queue ãTarantool 1.6ãããã³Tarantool Queueã䜿çšããŸãã
Tarantool Queueã©ã€ã³ã¯ãããªã倧ããªè² è·ã«èããŸãã GitHubã«èª¬æããããŸãã Tarantool Queueã䜿çšãã1ã€ã®ã€ã³ã¹ã¿ã³ã¹ã§ã¯ãqueue.create_tubeãåŒã³åºãããšã§è€æ°ã®è«çãã¥ãŒãäœæã§ããŸãã è«çãã¥ãŒã¯ãã¥ãŒããšåŒã°ããŸãã ããã€ãã®ã¿ã€ãã®è«çãã¥ãŒããµããŒããããŠããŸãã Tarantool Queueã«ã¯ã
take/ack
ã¡ã«ããºã ããããŸãã å®è¡åŒã³åºãã¯ãã¿ã¹ã¯ããé²è¡äžããšããŠããŒã¯ããŸãã
ack
åŒã³åºããšãã¿ã¹ã¯ããã¥ãŒããåé€ãããå®è¡ãæåããããšã確èªãããŸãã
ack
åŒã³åºãã«å°éããªãå Žåãå¥ã®ããã»ã¹ãã¿ã¹ã¯ã
take
ãå®è¡ã
take
ã
delay
ãã©ã¡ãŒã¿ãŒã䜿çšããŠãã¿ã¹ã¯ã®å®è¡ããã°ããé ãããããšãã§ããŸãã ãã¹ãŠã®ãã¥ãŒã«ãã®ãããªæ©èœãšããã©ãŒãã³ã¹ãããããã§ã¯ãããŸããã
ãŠãŒã¶ãŒã¹ãã¬ãŒãžãšãã¥ãŒã·ã¹ãã ã®äž¡æ¹ã«Tarantoolã䜿çšãããšã䜿çšãããã¯ãããžãŒã®èŠ³ç¹ãããµãŒãã¹ãã·ã³ãã«ã«ãªããŸãã Tarantool Queueã®äœ¿çšã¯ãªãã·ã§ã³ã§ãã TarantoolãšLuaã¯ãç¬èªã®ãã¥ãŒãå®è£ ããæ©äŒãæäŸããŸãã
Tarantoolãã€ã³ã¹ããŒã«ããgithub.com / tarantool / queueã/ usr / local / luaãã£ã¬ã¯ããªã«é 眮ããŸãã Tarantool config /etc/tarantool/instances.enabled/q1.luaã§ã次ãæå®ããŸãã
#!/usr/bin/env tarantool package.path = package.path .. ';/usr/local/lua/tarantool-queue/?.lua' box.cfg{listen = 3301, slab_alloc_arena = 2} queue = require 'queue' queue.start() box.queue = queue
ã€ã³ã¹ã¿ã³ã¹ããã¥ãŒã§éå§ããŸãã
tarantoolctl start q1
ã³ã³ãœãŒã«ã«è¡ããŸãïŒ
# tarantoolctl enter q1 /usr/bin/tarantoolctl: Connecting to /var/run/tarantool/q1.control /usr/bin/tarantoolctl: connected to unix/:/var/run/tarantool/q1.control unix/:/var/run/tarantool/q1.control
ã²ã¹ãã¢ã¯ã»ã¹ãèš±å¯ããè«çãã¥ãŒ
q1
ãäœæããŸãã
q1.control> box.schema.user.grant('guest','read,write,execute','universe') q1.control> queue.create_tube('q1', 'fifo') ^D
次ã®ããã«1ã¿ãŒã³ãã¬ãŒãã§ããŸãã
queue = Tarantool.Queue(host="localhost", port=3301) while True: task = queue.take(tube="q1") process(task) task.ack()
Nåã®ãã¥ãŒãã¬ãŒãããããã«ãNåã®ããã»ã¹ãäœæã§ããŸãã åããã»ã¹ã§ãç®çã®ãã¥ãŒã«æ¥ç¶ãããŸã£ããåããµã€ã¯ã«ãå®è¡ããå¿ èŠããããŸãã ããã¯å®çšçãªã¢ãããŒãã§ããããã¥ãŒãå€æ°ããå Žåã¯ãTarantool Queueãžã®æ¥ç¶ãå€ããªããŸãã ãµãŒããŒã®ç©çã¡ã¢ãªãæ¶è²»ããå€ãã®ããã»ã¹ãèµ·åãããŸãã ãå€ãã®æ¥ç¶ãã§ã¯ãTarantoolã§ã®äœæ¥ãå¯èœãªéãå¹æçã«ãªããŸããã ãŸããããã»ã¹ã§ã¯ãGoogleããã³AppleãµãŒããŒãžã®æ¥ç¶ãç¶æããå¿ èŠããããŸãã ç¹°ãè¿ããŸãããä¿æããŠããGoogleãŸãã¯AppleãµãŒããŒãžã®æ¥ç¶ãå°ãªãã»ã©ãããŒãããè² è·ãå°ãªããªãããããµãŒããŒã®ãªãœãŒã¹ãããå€ã䜿çšã§ããŸãã
ãPythonã®Tarantoolã䜿çšããéåææäœãã®èšäºã§ãTarantoolãžã®åäžã®æ¥ç¶ã䜿çšãããšããã©ãŒãã³ã¹ãé¡èã«åäžããçç±ã詳ãã説æããŸããïŒããã¯ã¯ãŒã¯ããŒãã«ãšã£ãŠéåžžã«éèŠã§ãïŒã ãã®ã¢ãããŒãã¯ããã§é©çšã§ããŸãã ãœãŒã¹ã®æ¬äŒŒã³ãŒããå°ãå€æŽããŠããã¥ãŒãããéããŸãã ãããasyncioã«é©åãããŸãã
import asyncio import aiotarantool_queue @asyncio.coroutine def worker(tube): while True: task = yield from tube.take(.5) if not task: break # process(task.data) yield from task.ack() loop = asyncio.get_event_loop() queue = aiotarantool_queue.Queue("127.0.0.1", 3301, loop=loop) workers = [asyncio.async(worker(tube), loop=loop) for tube in (queue.tube('q1'), queue.tube('q2'), queue.tube('q3'))] loop.run_until_complete(asyncio.wait(workers)) loop.run_until_complete(queue.close()) loop.close()
1ã€ã®ããã»ã¹ã§ããã¥ãŒãžã®æ¥ç¶ãäœæããŸãã ãã¹ãŠã®è«çãã¥ãŒã«å¯ŸããŠtake / ackã«ãŒãã䜿çšããŠã³ã«ãŒãã³ãäœæããŸãã ã€ãã³ãã«ãŒããéå§ãããã¹ãŠã®ãã¥ãŒãã¬ãŒãããŸãã ãããããã¥ãŒã€ã³ã°ãã¿ãŒã³ã®æ§åã§ãã
ã³ãŒãã¯ç·åœ¢ã®ãŸãŸã§ãããã³ãŒã«ããã¯ã¯ãããŸããã ãŸãããã®ã³ãŒãã®ã
aiotarantool_queue
ãã§ã¯ããã¥ãŒããã®ã¿ã¹ã¯ãããã³ãã«ãã«ãã£ãŠå·®ãåŒããããšããäºå®ãé ãããŠããŸã-ããã¯ãã¹ãŠ
aiotarantool_queue
åŸãããŸãã æåŸ ãããããã¥ãŒãšã¿ã€ã ã¢ãŠããåŒãåºããŸãïŒ ãã£ããã ãã¡ããããã¹ãŠã®ãµãŒããŒã³ã¢ãCPUã«ããŒãããã«ã¯ããã®ãããªããã»ã¹ãããã€ãå®è¡ããå¿ èŠããããŸãããããã¯æ¢ã«æè¡çãªåé¡ã§ãã Pythonããã»ã¹ã§ã®ãã¥ãŒã€ã³ã°ã¯æ¬¡ã®ããã«ãªããŸãã ã³ã«ãã³ã®ä»£ããã«ãããã»ã¹ããããŸãã ãŸããåæã¢ãããŒãã䜿çšãããšãã³ãŒãã¯ããã«è€éã«ãªããæãéèŠãªããšãšããŠãçç£æ§ãäœäžããå¯èœæ§ããããŸãã
ãã ããasyncioã䜿çšããããšã«ã¯æ¬ ç¹ããããŸãã ãµãŒãããŒãã£ã®ã©ã€ãã©ãªãåäœãããå¿ èŠããããŸãããããã¯ããã»ã©é£ãããããŸãããããããã®ã©ã€ãã©ãªã®ã³ãŒããæ éã«ã¬ãã¥ãŒããasyncioåŒã³åºãã䜿çšããŠåäœã調æŽããå¿ èŠããããŸãã çç£çãªãµãŒãã¹ãå¿ èŠãªå Žåã¯ãasyncioã®äžã§ãµãŒãããŒãã£ã©ã€ãã©ãªã®äœæ¥ããµããŒããããã¹ãŠã®åªåãæ£åœåãããŸãã
ããããRedisãšRabbitMQã¯ã©ãã§ããããïŒ
RedisãRabbitMQã§ã¯ãªãTarantool Queueã䜿çšããçç±ã¯äœã§ããïŒ ç¹å®ã®è£œåã«æå©ãªéžæã¯ããã»ã©åçŽã§ã¯ãããŸãã-RedisãšRabbitMQã®äž¡æ¹ãæ€èšããŸããã Redisã«ã¯ãããã¿ã€ãããããŸããã ãããã®ãœãªã¥ãŒã·ã§ã³ã¯ãã¹ãŠãååãªããã©ãŒãã³ã¹ãåããŠããŸãã ããããããã§ã®åé¡ã¯ã誰ãéãããã ãã§ã¯ãããŸãã...
ãŸãããã¥ãŒãã¡ã¢ãªå ã§ã¯ãªãä¿¡é Œã§ãããã®ã«ãããã®ã§ãã WALãåããTarantoolã¯ãRedisãRabbitMQãããä¿¡é Œæ§ãé«ãèŠããŸãã
åãã¥ãŒã·ã¹ãã ã«ã¯ç¬èªã®ç¹æ§ããããŸãã Redisã«ã¯pub / subã¡ã«ããºã ããããåé¡ã®è§£æ±ºã«ã¯é©ããŠããŸãã-ãã¥ãŒãå¿ èŠã§ãã Redisã«ã¯ãªã¹ããšrpush / blpopæäœããããããŒã¿ã衚瀺ãããã®ãããã¯ããŠåŸ æ©ããŸãããtake / ackã¡ã«ããºã ã¯ãããŸããã ç§ãã¡ã®çç£ã§ã¯ããã®ç¹å®ã®ã¡ã«ããºã ã«ãã£ãŠä¿¡é Œæ§ãæäŸãããŸã-ãããæé«ã§ããããšãç¹°ãè¿ã蚌æãããŠããŸãã
RabbitMQã¯ããã¥ãŒã®ããŸããŸãªãã¿ãŒã³ãè±å¯ã§ãã åé¡ã解決ããã«ã¯ãRabbitMQæ©èœã®äžââéšã®ã¿ãå¿ èŠã§ãã ãã®ããã©ãŒãã³ã¹ã¯éåžžã«é«ãã§ããããã£ã¹ã¯ãžã®ããŒã¿ã®ä¿åããªã³ã«ãããšãè² è·æã®ããã©ãŒãã³ã¹ãå€§å¹ ã«äœäžããŸãã RabbitMQãå®è¡ããã«ã¯ãRabbitMQã€ã³ã¹ã¿ã³ã¹ãåèµ·åããã ãã§ãªããéçšäžã®åé¡ã蚺æã§ããçµéšè±å¯ãªã·ã¹ãã 管çè ãå¿ èŠã§ãã
RabbitMQã®ç¹å¥ãªæ³šæã¯ãPython APIãšasyncioã®ã³ãã¯ã¿ã«å€ããŸãã ãã¥ãŒAPIã¯ã³ãŒã«ããã¯ã«å®è£ ãããŸãã ã³ãŒã«ããã¯ããã®ã³ãŒãã¯è€éã«ãªããä¿å®ãé£ãããªããŸãã asyncioã§message.ackãäœæããã«ã¯ã FutureãäœæããŠåŸ ã€å¿ èŠããããŸãã ãã®ãããªã³ãŒãã¯éåžžã«è€éã«èŠããŸãã ãŸãã1ã€ã®æ¥ç¶ã«è€æ°ã®put / takeãéä¿¡ããããšãã§ããŸããã§ããã
asyncioãåããRedisã®æ¹ãã¯ããã«åªããŠããŸããasyncioã®äœæè èªèº«ã«ããçŽ æŽãããã³ãã¯ã¿ããããŸãã éåžžã«é«éã«åäœããŸãã
Redisããã³RabbitMQã§ã¯ãTarantoolã®ãããªããŒã¿ããŒã¹ãšluaã«ãã®ãããªããŒã¿çµ±åã¯ãããŸããã ååãšããŠãçç£ã¿ã¹ã¯ã«ã¯ãããã¯ã¹ããããå°ããããžãã¯ããå¿ èŠã§ãã Tarantoolã§ã¯ãããã¯luaã®ãããã§ç°¡åã«å®çŸã§ããŸãã ããšãã°ãã«ãŠã³ã¿ãŒãŸãã¯ããŒã¿ãã£ãã·ã¥ã®ä¿åãéå§ãããããã¥ãŒã«å ¥ããããã€ã³ã¹ã¿ã³ã¹ã®çµ±èšãçŽæ¥ä¿åãããã§ããŸãã ããã«ãããTarantoolã¯ããŸããŸãªåé¡ã解決ããã®ã«äŸ¿å©ã§ãã
ãŸãšãããš
è€æ°ã®ãµãŒããŒã§ãã¥ãŒã€ã³ã°ã·ã¹ãã ã䜿çšããŠããŠãŒã¶ãŒããŒã¹å šäœãã§ããã ãè¿ éãã€å¹ççã«äžŠååããæ¹æ³ã®ã¢ãŒããã¯ãã£ãæ€èšããŸããã Tarantool Queueãšasyncioã䜿çšãããã¿ãŒã³ã調ã¹ãŸããã ãã¥ãŒã·ã¹ãã ã䜿çšããã³ãŒãéçºã®åé¡ã«æ³šæãæããŸããã RabbitMQãšRedisã®åé¡ãããã³Tarantool Queueã®å©ç¹ã調ã¹ãŸããã
ãã®æ å ±ãHabrã®èªè ã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã 誰ãããã¥ãŒã䜿çšããã±ãŒã¹ãå ±æãããã®ãœãªã¥ãŒã·ã§ã³ãŸãã¯ãã®ãœãªã¥ãŒã·ã§ã³ãéžæããçç±ã«ã€ããŠè©±ããŠããããšããããã§ãã
èšäºã®å·çã«äœ¿çšããããªã³ã¯ïŒ
- Tarantool-Luaã¢ããªã±ãŒã·ã§ã³ãµãŒããŒtarantool.orgã§å®è¡ãããNoSQLããŒã¿ããŒã¹
- Python asyncio asyncio.org
- asyncio github.com/shveenkov/aiotarantoolãšé£æºããããã®Tarantoolæ¥ç¶ãã©ã€ããŒ
- python asyncioã§åäœããTarantool Queueãã€ã³ãã£ã³ã°github.com/shveenkov/aiotarantool-queue-python
- My MirãœãŒã·ã£ã«ãããã¯ãŒã¯habrahabr.ru/company/mailru/blog/228131ã®ãã¥ãŒåŠçã€ã³ãã©ã¹ãã©ã¯ãã£
- Target Mail.Ruã·ã¹ãã ã®äŸã®REST APIã§ããã·ã¥éç¥habrahabr.ru/company/mailru/blog/232981
- Pythonã§ã®Tarantoolã«ããéåææäœhabrahabr.ru/company/mailru/blog/254727