VKontakteã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ïŒå ¬åŒã§ã¯ãªãã«ããŠãïŒãæšå¹Žäœ¿çšããå Žåããã®è³æã¯ä»åã®ããã·ã¥éç¥ã®åäœã«é¢ããå°ããªããŒã¿ãæããã«ããŸãã ããã·ã£ãŒã¯Goã§å®è£ ããã1æ¥ãããæ倧90åã®ããã·ã¥ã4ã€ã®ã¿ãŒã²ãããã©ãããã©ãŒã ïŒGCMãAPNSãMPNSãWNSïŒã«éä¿¡ããŸãã
ãã®æçš¿ã§ã¯ãéã®å šäœçãªã¢ãŒããã¯ãã£ãåé¡ãšãã®åé¿çãè² è·ããœãªã¥ãŒã·ã§ã³ã®ããã©ãŒãã³ã¹ã«ã€ããŠè©±ãããšã«ããŸããã ããããã®æçŽãšå°ããªã³ãŒãã
ã¢ãŒããã¯ãã£ã¯åçŽã§ããäœããã®ã€ãã³ããçºçããããã«ã€ããŠNçªç®ã®åä¿¡è ã«éç¥ããå¿ èŠããããããã·ã¥ã®ã³ã³ãã³ããããŒãœãã©ã€ãºãããŸãã ããã·ã¥ã®ããã¯ãååä¿¡è ïŒæ¥ç¶ãããŠãããã¹ãŠã®ããã€ã¹ïŒã«å¯ŸããŠåœ¢æãããéä¿¡ãã¥ãŒã«è¿œå ãããŸãã
pusherkaã¯ããããã®ããã·ã¥ãããããåãåºããå¿ èŠã«å¿ããŠéä¿¡ããçµ±èšãæŽæ°ããå¿ èŠããããŸãã
å€éšAPIãä»ããŠã®ã¿ãã¥ãŒããåºãããšãã§ããŸããå€éšAPIã¯ãèŠæ±ããããã©ãããã©ãŒã ã®ã¿ã«å€§ç ²ã®ããã¯ãæäŸããŸãïŒããã¯ä»¥äžã§å¿ èŠã§ãïŒã ãã¹ãŠã®ãã©ãããã©ãŒã ã¯1ã€ã®ããã»ã¹ã§åŠçãããã¿ã€ããã©ã®ããã«ã©ã®ããã«åŠçãããããã§ã«ç¥ã£ãŠãããã³ãã©ãŒã«ããã·ã¥ãåæ£ããŸãã
ã¹ããŒã ã¯åçŽåãããŠããŸãã察å¿ããæ¥ç¶ââæ°ã¯ãã¹ããŒã ã®ããã«1ã€ãã€ã§ã¯ãªããã°ã«ãŒãåããããããã¯ãè¡ãæ¥ããå¿ èŠããããŸãã
APIããããã·ã¥ãååŸãã
ããã·ã¥ãååŸããå¯äžã®æ¹æ³ã¯HTTPSã¢ã¯ã»ã¹ãåããå€éšAPIã§ãããããåä¿¡ã¯åçŽã«http.Clientãä»ããŠåäœããããŒãã¢ã©ã€ãããµããŒãããããã«MaxIdleConnsPerHostãå¢ãããŸãã ãã®å ±éã®http.Clientãå ±æããããã€ãã®ãŽã«ãŒãã³ã¯ãåžžã«æ°ããAPIã䜿çšããŠããã·ã¥ãè¡ããŸãã å®å šãªããã¯ãïŒ1ã3kããã·ã¥ã®ãªãŒããŒã§ïŒå°çããå Žå-次ã®ãªã¯ãšã¹ããããã«éä¿¡ãããå¿ èŠãªãã®ããã¯ããã«å°ããå Žåã¯ããªã¯ãšã¹ãã¯å°ãã®éåæ¢ããŸãã
ããã§ã¯ã1ç³ã§2矜ã®é³¥ãæãŸããŸãããã¥ãŒã«å ¥ããããé床ãäœäžãå§ããå€éšããŒãã«åé¡ãããå Žåã¯ãè² è·ãæžãããŸãã èŠæ±ããŸã£ããééããªãããŸãã¯ãã³ã°ããªãå Žåã¯ãäžå®æéïŒçŽ2ã3åïŒåŸã«ãã¹ãŠã®æ¥ç¶ãéããŠãæ°ããhttp.Clientãªããžã§ã¯ããäœæããŸãã
ãã®çµæãåŠççšã®æ°é®®ãªããŒã¿ã®äžå®ã®ã¹ããªãŒã ãååŸããã¿ãŒã²ãããã©ãããã©ãŒã å šäœã§é©åãªãã¥ãŒïŒéåžžã®ãããã¡ãã£ãã«ïŒã«åæ£ããŸãã
åæã«ããã¥ãŒã®æºæ¯ãç£èŠããããã¥ãŒãéåžžã«åŒ·ãè©°ãŸããšïŒ50ïŒ ä»¥äžïŒãã¡ãŒãªã³ã°ãªã¹ãã¯APIã«ãã®ã¿ã€ããèŠæ±ããªããªããŸãã
éä¿¡è ãããã·ã¥ãã
ããã·ã³ã°ããžãã¯ã¯ãã©ãããã©ãŒã ã«ãã£ãŠç°ãªããŸãããäœããã®æ¹æ³ã§ãã©ãããã©ãŒã ãã¯ãŒã«ãŒããŒã«ã«çµ±åããå ±éã®ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããŸãã
ãããã®ããŒã«ã®ãµã€ãºã¯ãåä¿¡ããããã·ã¥ã®ãã£ãã«ã®ãµã€ãºãç£èŠããäžè¬çãªæ¥ç¶ãããŒãžã£ãŒã«ãã£ãŠç®¡çãããŸãã å æçããã£ãã«å®¹éã®10ïŒ ãè¶ ããå ŽåããããŒãžã£ãŒã¯ãããã·ã¥ã®åä¿¡è ãšããŠç»é²ãããŠããç¹å®ã®ãã©ãããã©ãŒã ããã³ã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ã®æ§æã§èš±å¯ãããŠããå¶éå ã§ããŒã«ãæ¡åŒµããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®äŸ¡å€ãé«ãã»ã©ãããå€ãã®å¯èœæ§ããããŸã:)ããããçš®é¡ã®ãµãŒãããŒãã£ã¢ããªã±ãŒã·ã§ã³ã«ããã·ã¥ãéä¿¡ããå¿ èŠããªãã£ããšããŠãã蚌ææžãçŸåšã®ã¢ããªã±ãŒã·ã§ã³ç»é²ã远跡ããŠããããã§ã¯ãããŸããã
ããŒã«ã®å®¹éã¯ã段éçã«ïŒäžåºŠã«1ã€ã§ã¯ãªããããã¯ã§ïŒå¢å ãã2ã€ã®ãšã¯ã¹ãã³ã·ã§ã³éã®æå°æéã䜿çšããŠãæ°ããäœæããããšã¯ã¹ãã³ã·ã§ã³ãåäœãªãºã ã«å ¥ãããã«ããŸãã æ§æã§ã¯ã倧èŠæš¡ãªåé¡ã®å Žåãæ倧å¶éãéåžžã«é«ãèšå®ãããŸãïŒæ®ãã®éšåãå¿ èŠä»¥äžã«åŒãåºããããããé ä¿¡é 延ãå§ãŸãåã«ããªããšãããŠéã®80ïŒ ãå£ããŸããïŒã
ããããã®æ¥ç¶ããããŸãããumilit -nã1äžå以äžã®èšè¿°åã¬ãã«ã«äžããå¿ èŠããããŸãã ããŠãGoã§ã¯ã次ã®ããã«å¶éãããã«èš±å®¹æ倧å€ã«åŒãäžããŸãã
var rLimit syscall.Rlimit if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { return nil, err } if rLimit.Cur < rLimit.Max { rLimit.Cur = rLimit.Max syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) }
ç¹å®ã®ã¿ãŒã²ãããã©ãããã©ãŒã ïŒgcmãªã©ïŒã®äžè¬çãªãã£ãã«ã¯ãç»é²ãããåã¢ããªã±ãŒã·ã§ã³ã®å€ãã®ãã£ãã«ïŒããã³ããããåŠçããããã®ã¯ãŒã«ãŒããŒã«ïŒã«åå²ãããŸãã ç¹å¥ãªãŽã«ãŒãã³ã¯ãç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ã®ãã£ãã«ãä»ããŠå€§ç ²ã®çä¿¡ã¹ããªãŒã ãæ£ä¹±ãããŸãã ããã¯ãç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ã®ã¯ãŒã«ãŒãäœæããããŒã«ã®ã¹ã±ãŒãªã³ã°ã®åºçªã§ãã æé·ããå Žæããªãå Žåã2ã€ã®éžæè¢ããããŸããã¢ããªã±ãŒã·ã§ã³ã®åé¡ã¯ãç§ãã¡ã«ãšã£ãŠéèŠãã©ããã§ãã
éèŠãªã¢ããªã±ãŒã·ã§ã³ã®å Žåãçä¿¡ããã·ã¥ãã£ãã«ã®ã¬ã€ã¯ãåæ¢ããã ãã§ãè©°ãŸãå§ããAPIããããã·ã¥ãåä¿¡ããã¯ãŒã«ãŒã«è¡šç€ºããããªã¯ãšã¹ãããç¹å®ã®ãã©ãããã©ãŒã ãåé€ããã ãã§ãã ãããŠãããã·ã¥ã¯ä»ã®ããã·ã£ãŒã«åé åžããããããã¥ãŒãæ¡å€§ãå§ããŸããããã¯æ¢ã«ã¢ãã¿ãªã³ã°ã§ç¢ºèªã§ããŸãã
ãŸããã¢ããªã±ãŒã·ã§ã³ãç¹ã«éèŠã§ã¯ãªããã¢ããªã±ãŒã·ã§ã³ã®å¶éã䜿ãæããããå Žåãæ²ããããšã«ãããã·ã¥ã¯åŠçãããã«ç Žæ£ãããŸãïŒãã ãããããã®ç Žæ£ã¯çµ±èšã«è¡šç€ºãããŸãïŒã
ç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ã«é¢ããåé¡ã®æ°ïŒäžæ£ãªèšŒææžããµãŒããŒãžã®æ¥ç¶ã®åæãéä¿¡æã®ã¿ã€ã ã¢ãŠããªã©ïŒã«é¢ããå éšçµ±èšãïŒã¢ããªã±ãŒã·ã§ã³å ã§ïŒä¿æããããå¿èããè¶ ãããšããã®ãããªã¢ããªã±ãŒã·ã§ã³ã¯äžæçãªçŠæ¢ãåãåããŸã-ãã¹ãŠã®ããã·ã¥ã¯ç Žæ£ãããŸãçŠæ¢æéå šäœãåŠçããŸãã
ããã¯ããµãŒãããŒãã£è£œã®1æ¥ã¢ããªã±ãŒã·ã§ã³ãŸãã¯çªç¶æ®åããã¢ããªã±ãŒã·ã§ã³ã§ãéåžžã®èšŒææžããªããã¿ãŒã²ãããã©ãããã©ãŒã ã«å¯ŸããŠããå€ãã®ããã·ã¥å¶éãçæããå Žåã«éåžžã«äŸ¿å©ãªæ©èœã§ãã ãããã®ã¢ããªã±ãŒã·ã§ã³ã®ä»£è¡šè ã«èªåãã¡ã§æçŽãæžããŠãããã·ãŒãæ£åžžã«åãåãããã«èªå® ã§ãã®éšåãçµããã®ãè¯ããšã»ã®ããããå ŽåããããŸããã
ãã¡ãããããŒãã¢ã©ã€ããšèšŒææžãã£ãã·ã³ã°ã®ååã§ãã¹ãŠãè¡ãå¿ èŠããããŸããããããªããšãåžžã«çžäºäœçšãšã©ãŒãçºçããåæ¥ç¶ããæ¹æ³ããªããããã¢ããªã±ãŒã·ã§ã³ãå³åº§ã«å©å®³é¢ä¿ãç²åŸããŸãã
ãã¹ãŠã®ã¯ãŒã«ãŒã«ã¯ãé害ãçºçããå Žåã«å éšè»¢éãããã¡ãŒããããŸããããã¯èŽåœçã§ã¯ãªããšèŠãªãããŸãïŒããšãã°ãèŠæ±ã¿ã€ã ã¢ãŠãããŸãã¯502å¿çã³ãŒãïŒã 次ã®ããã«ãªããŸãã
for { select { case push := <-mainChan: send(push) case push := <-resendChan: send(push) default: // ... } } func send(push Push) { if !doSmth(push) { resendChan <- push } }
selectã®ããã€ãã®ãªãã·ã§ã³ããéžæããé åºãä¿èšŒãããŠããªããããäž¡æ¹ã®ãã£ãã«ããé çªã«éžæãããŸãã ãããè¶ ããŠãåéä¿¡ã®æ°ãåéä¿¡åã®ã¿ã€ã ã¢ãŠãã«ã¯ãŸã å¶éããããŸãããããã¯ãã§ã«è³æã®ç¯å²ãè¶ ããŠããŸãã
APNS
äœãããïŒä»ã®ãšããïŒïŒããªã³ãŽçç£ã®ããã·ã¥ã¯äœæ¥ãç°ãªãããªã¢ãŒãåŽãšã®éä¿¡ã¯ãã€ããªãã±ãããéä¿¡ããtlsæ¥ç¶ãä»ããŠè¡ãããŸãã
ããã¥ã¡ã³ãã«ãããšããšã©ãŒã¡ãã»ãŒãžïŒå€ãèªèšŒã誀ã£ãŠçæããããªã¯ãšã¹ããªã©ãçºçããå ŽåïŒã¯ãåŸã§åãæ¥ç¶ãçµç±ããã¯ãã§ãã
ãªããªã åãªã¯ãšã¹ãã«å¯ŸããåçïŒéåžžã¯ååšããŸããïŒã®åŸ æ©ãé ããããããéä¿¡æžã¿ã®ããã·ã¥ã®ãªã¹ããšç¢ºèªæžã¿ã§ã¯ãªãããã·ã¥ã®ãªã¹ãïŒlist.Listã䜿çšïŒã«ãã¹ãŠã®éä¿¡æžã¿ããã·ã¥ãšå°ãã®è¿œå æ å ±ãè¿œå ããå¿ èŠããããŸãã ãããŠãçããåŸ ã¡ãŸãã åŸ ã€æéãããŸãæ確ã§ã¯ãããŸããã ãã®å ŽåãåŸ æ©æéã¯2ç§ã«éžæãããŸããïŒçºçããªãã£ããããååã§ã¯ãããŸããã§ããïŒã
å¿çãåä¿¡ãããšãäœããã®ãšã©ãŒãçºçãããããã¹ãŠãæ£åžžã§ããïŒåãã±ããã§éä¿¡ãããïŒããã·ã¥èå¥åãèŠã€ããŸãïŒã¯ãããã®ãããªåçãªãã·ã§ã³ããããŸãïŒã ãããã£ãŠãæå®ããããã®ãžã®ãã¹ãŠã®ããã·ã¥ã¯ãé ä¿¡æã«ç¢ºèªæžã¿ãšèŠãªãããšãã§ããŸããå ·äœçã«ã¯ããã®ããã·ã¥ã¯ç Žæ£ãããããåéä¿¡ãããŸãã æå®ããåŸã®ãã¹ãŠã®ããã·ã¥ã¯ã次ã®ãšã©ãŒã¡ãã»ãŒãžãŸã§ããŸãã¯ã¿ã€ã ã¢ãŠãåŸã«ãªã¹ãã«æ®ããŸãã 2ç§ä»¥äžã©ã€ã³ã«æšªããã£ãŠããããã·ã¥ããã°ã¯ãã¿ã€ã ã¢ãŠãããšèŠãªãããŸãã
ããã«ãAppleãµãŒããŒãžã®åå¥ã®æ¥ç¶ããããŸãããããä»ããŠãæªç»é²ã®ã¢ããªã±ãŒã·ã§ã³ã®ããŒã¿ãå«ãçä¿¡ãã±ãããåä¿¡ããŸãã ã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ããšã«1ã€ã®åå¥ã®gorutinkaã«ãã£ãŠåŠçãããŸãã
ãã®çµæãåä¿¡ãã£ãã«éã§ã®ããã·ã¥ã®ç¡é転éãæªç¢ºèªããã³åéä¿¡ã®ãã¥ãŒãåŸãããŸãïŒããã¯ããã·ã¥ããšã«ç¹°ãè¿ãçºçããå¯èœæ§ããããŸãïŒã
ããã«ãããã¥ã¡ã³ãã«èšèŒãããŠããªããšã©ãŒãçºçããå Žåãããããšãè¿œå ã§ããŸãã ãŸãã¯ïŒæãäžè¬çãªïŒæ¥ç¶ã¯ããšã©ãŒéç¥ãªãã§åæãããŸãã çŸããã¯ïŒ
å®è£ ã¯ãã¢ãã€ã«ããã»ããµi7-4500UãæèŒããã©ãããããïŒãã¡ãããã¹ãã®ååã§ïŒã§1æ¥ãããçŽ14åapnã®ããã·ã¥ïŒããã¯ãã¹ãŠã§ã¯ãªããé ä¿¡ãŸãã¯å»æ£ã®æ°ã ãã§ãïŒïŒ1ããŒã¯ããã1ç§ãããçŽ3äžã3äž3åïŒããã³ãããŸãã
ããããæè¿åŠãã ããã«ãAppleã¯ä»ã®ãŠãŒã¶ãŒãšåæ§ã«ãhttpãªã¯ãšã¹ããä»ããŠãã®ã¹ããŒã ãå®è£ ããäºå®ã§ãã èŠãŠã¿ãŸãããã
Gcm
æãé©åãªãã©ãããã©ãŒã ã åŽåè ã®è«çã¯ãæåéã1ã2æ¥ã§æžãããŠããããã以æ¥åçŽã«æ©èœããŠããŸãã MaxIdleConnsPerHostïŒæ°åïŒã§ããã«http.ClientãäœæããPOSTèŠæ±ãéä¿¡ããŸãã ãµãŒããŒã¯è¿ éã«å¿çããããã¥ã¡ã³ãã¯åªããŠããŸãã ããŒã¯æã«ã¯ã1ç§ããã100kã®ããã·ã¥ã«è¿ã¥ããŸãã
XMPPã¯ãªãã·ã§ã³ãè©ŠããŸããã§ããããæéããããŸãã®ã§ãè©ŠããŸãã ãããããããã¯åäœããŸã-觊ããªãã§ãã ãããã
MPNSãWNS
ããã¯ãã¹ãŠã®ãªãã·ã§ã³ãç¹ã«MPNSã®ææªã§ãã ããã§ã¯ã1ã2ç§éã®å¿çãåŸ ã£ãŠããŸãïŒåã«èšèã¯ãããŸããïŒïŒããšã©ãŒã®ããxmlã®ä»£ããã«stackracesãåãåããŸãïŒããã¯ã1ã2ç§åŸ ã£ãåŸïŒã
åçã®äŸ
<ïŒDOCTYPE html> \ r \ n <html> \ r \ n <head> \ r \ n <title>ããã°ã©ã ã®å®è¡ãç¶ç¶ããããã®ã¡ã¢ãªäžè¶³<\ / Title> \ r \ n
...
OutOfMemoryExceptionïŒããã°ã©ã ã®å®è¡ãç¶ç¶ããã«ã¯ã¡ã¢ãªãäžè¶³ããŠããŸãã] \ R \ n System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonatedïŒSafeUserTokenHandle userTokenãString cmdãString currentDirãTempFileCollection tempFilesãStringïŒoutputNameãStringïŒoutputMameãStringïŒoutputName \ r \ n
...
ASP.NETã¯<customErrors mode = \ "Off \" \ />ã䜿çšããŠè©³çŽ°ãªãšã©ãŒã¡ãã»ãŒãžã衚瀺ããããã«æ§æãããŠããããããã®ãšã©ãŒããŒãžã«ã¯æ©å¯æ å ±ãå«ãŸããå ŽåããããŸãã å®çšŒåç°å¢ã§ã¯ã<customErrors mode = \ "On \" \ />ãŸãã¯<customErrors mode = \ "RemoteOnly \" \ />ã®äœ¿çšãæ€èšããŠãã ããã
...
...
OutOfMemoryExceptionïŒããã°ã©ã ã®å®è¡ãç¶ç¶ããã«ã¯ã¡ã¢ãªãäžè¶³ããŠããŸãã] \ R \ n System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonatedïŒSafeUserTokenHandle userTokenãString cmdãString currentDirãTempFileCollection tempFilesãStringïŒoutputNameãStringïŒoutputMameãStringïŒoutputName \ r \ n
...
ASP.NETã¯<customErrors mode = \ "Off \" \ />ã䜿çšããŠè©³çŽ°ãªãšã©ãŒã¡ãã»ãŒãžã衚瀺ããããã«æ§æãããŠããããããã®ãšã©ãŒããŒãžã«ã¯æ©å¯æ å ±ãå«ãŸããå ŽåããããŸãã å®çšŒåç°å¢ã§ã¯ã<customErrors mode = \ "On \" \ />ãŸãã¯<customErrors mode = \ "RemoteOnly \" \ />ã®äœ¿çšãæ€èšããŠãã ããã
...
ææªã®éšåã¯ãæã ãã®ãããªçãã¯ããã·ã¥ãåä¿¡ãããªãã£ããšããæå³ã§ã¯ãªããšããããšã§ãã ãããŠãç§ãã¡ã®åŽããåéä¿¡ãããšãããã€ã¹ã«2ã€ã®åäžã®å€§ç ²ãå°çããŸãã ãããŠãçµå±ã®ãšããã人ã ã¯ååãšããŠåœŒãã®äžåšããã2ããã·ã¥ã«åæºããŠããŸãã
ãããšã¯å¥ã«ã蚌ææžã䜿çšããŠéä¿¡ããããã«å¿ èŠãªTLSåããŽã·ãšãŒã·ã§ã³ã«ã€ããŠèª¬æãã䟡å€ããããŸãïŒèšŒææžããªããšããã«éä¿¡å¶éã«éããïŒããGoã§ã¯ãµããŒããããŠããããéåžžã©ãã§ã飲ãŸããŸãã
ãããè¡ãã«ã¯ãcgoã©ãããŒãä»ããŠcurlçµç±ã§ããã·ã¥ãéä¿¡ããå¿ èŠããããŸãã ãããããœãªã¥ãŒã·ã§ã³ã®å®å®æ§ã¯ãŸããŸãã§ããæ°çŸäžã®ãªã¯ãšã¹ãããšã«ãã·ã¹ãã ã©ã€ãã©ãªå ã®ã©ããã§sigsegvããã£ããããæ©äŒããããŸãã ãã®åé¡ãäžæçã«è§£æ±ºããããã«ãcgoãä»ããcurlã®æäœã¯ãåãGoã®å¥ã®å°ããªïŒã400è¡ïŒã¢ããªã±ãŒã·ã§ã³ã«ç§»åããŸãããããã¯ãåå= push "http server => https curl tls renego client" => MSãµãŒããŒã§åäœããŸãã
ãã®ãããªã¢ããªã±ãŒã·ã§ã³ãåããå¥ã®å°ããªããŒã«ãèµ·åããããã®ãããŒãžã£ãŒã®ç£èŠãäœäžããŸãã ãããã®äžéãããã·ã¯ãå€éšãµãŒããŒã®å¿çã§ã¡ã€ã³ããã·ã¥ã«å¿çããå¿çæéããããã·å¿çã³ãŒãïŒå€éšãµãŒããŒã®å¿çã³ãŒãã«å ããŠïŒãªã©ããããã°ããã³çµ±èšçšã®ããããŒã«ã®ã£ã°ãè¿œå ããŸãã ããã«ãããäžå®å®ãªç°å¢ã§ç¢ºå®ã«ããã·ãŒãéä¿¡ã§ããŸãã
ãšããã§ãMaxIdleConnsPerHostã®ä»£ããã«ãCURLOPT_MAXCONNECTSãããã«èšå®ããããšãå¿ããªãã§ãã ãããããããªããšãCPUã§åã³é¢éžããŸããã
ãã ãããã®ãã©ãããã©ãŒã ã§ã¯ã2ã€ã®ç°ãªãç¬ç«ããèŠæ±ïŒããã³WNSã®3ã€ïŒã«ãã£ãŠããã·ã¥ããã³ãããžããã¹ãïŒã¢ããªã±ãŒã·ã§ã³ã¢ã€ã³ã³ã®æ°ïŒãèšå®ããå¿ èŠããããŸãã äžèšã®åŸ æ©æéãšã°ãªããã«2ãæããŠïŒ3ïŒé²ãã§ãã ãã...
çµ±èšåé
ã©ã®ããã«é£æºããŠããçµ±èšãå¿ èŠã§ãã ãããŠã詳现ã§ããã°ããã»ã©è¯ãã§ãã
ãã¥ãŒå å¡«ã³ãŒãïŒAPIã®åã®ã³ãŒãïŒãAPIã¡ãœããã®åäœãããã³é åžã¢ããªã±ãŒã·ã§ã³èªäœã®äž¡æ¹ãç£èŠãããŸãã
äž»ãªç¹åŸŽã¯éä¿¡æéã§ãïŒããã·ã¥çæã®ç¬éããç¹å®ã®ãµã€ãã®ãµãŒããŒãžã®ç¢ºèªãããéä¿¡ãŸã§ã«çµéããæéã é«éGCMããã³APNSã®å ŽåãåŠçæéå šäœã®å¹³åæéã¯çŽ60ã100ããªç§ã§ããMPNS/ WNSã®å Žåã¯ãã¹ãŠå¹žéã§ããMSãµãŒããŒãåäœé床ããéãéä¿¡ããããšã¯ã§ããŸããã
以äžã®çµ±èšãç¶æãããŸãã
- æå¹æéãåããéä¿¡æžã¿ãæåŠæžã¿ãéä¿¡æã«ãšã©ãŒãè¿ããæ°ïŒããŒã¯ã³ãéä¿¡ããéä¿¡ãã¥ãŒã«æ®ã£ãŠããéã¯ããŒã¯ã³ãç Žæ£ããéä¿¡ãè©Šã¿ãã«ãšã©ãŒãååŸããæ¥ç¶ããªã»ããããå¿ èŠããããŸãïŒ;
- åŠçæéïŒåãã©ãããã©ãŒã ããã³åã¢ããªã±ãŒã·ã§ã³ã®æå°/æ倧/å¹³å
- ããã»ã¹ã®çšŒåæéãcpuã®äœ¿çšïŒãŠãŒã¶ãŒãã·ã¹ãã ãioãã¢ã€ãã«ã§åå²ïŒãéããŠãããã¡ã€ã«èšè¿°åã®æ°ãã¡ã¢ãªæ¶è²»ïŒrssïŒãgcã®åèšå®è¡æéãããã³æåŸã®èµ·åã®æå°/æ倧/å¹³å
ãããã¯ãã¹ãŠåãAPIã§åéããããããã§éä¿¡ãããŸãã
ãã ããåãŽã«ãŒãã³ããã®ããã·ã¥ããšã«çµ±èšæ å ±ãä¿æããã®ã¯éåžžã«é«äŸ¡ã§ãïŒãããŠãæ°åããããŸãïŒã ãããã£ãŠããã¹ãŠã®ã¯ãŒã«ãŒã¯æåã«ããŒã«ã«ã§çµ±èšãåéããããŸã«ïŒæ°ç§ã«1åïŒå ±éã®å Žæã«ãããããŒãžããŸãã ãµã³ãã«ã³ãŒãïŒ
type Stats struct { sync.RWMutex ElapsedTime ... Methods ... AppID ... ... } addStatsTicker := time.Tick(5 * time.Second) for { select { case <-addStatsTicker: globalStats.Lock() gcm.stats.Lock() mergeStatsToGlobal(&gcm.stats) cleanStats(&gcm.stats) gcm.stats.Unlock() globalStats.Unlock() case push := <-mainChan: // , gcm.stats.Lock() statsMethodIncr(&gcm.stats, push.Method) statsAppIDIncr(&gcm.stats, push.AppID) gcm.stats.Unlock() send(push) // ... } }
éžæçãã®ã³ã°
äžè¬çãªçµ±èšã«å ããŠãéã䜿çšãããšãéžæããéãåŠçããéã®ãã¹ãŠã®éèŠãªæé ãèšé²ã§ããŸãã
ç¹å¥ãªãã©ã°ãæã€ããã·ã¥ããã¥ãŒããéä¿¡ãããå Žåããã®ããã·ã¥ãåŠçããããã®ãã¹ãŠã®ã¢ã¯ã·ã§ã³ã¯ãã¬ãŒã®ãããã°ãã£ãã«ã«éä¿¡ããããã¬ãŒã¯ãããã®ãã°ããã¹ãŠAPIã«éä¿¡ããŸãã æå/ãšã©ãŒã®ãã¡ã¯ãã ãã§ãªãããã¹ãŠã®éèŠãªè©³çŽ°ãåéãããŸãïŒéžææã®äž»èŠãªåå²ãå€æ°ãšãããã¡ã®å€ãããªç§ã®æ£ç¢ºãã®æ£ç¢ºãªæéã ããããã¹ãŠã«ããããããã®ãã°èªäœã®åé¡ç¹ããæ£ç¢ºã«ææ¡ããããšãã§ããŸããæšæ¥èª°ãããã®ãããªãšãã«ããã·ã¥ããªãã£ãããã2人ãåãããã«ãªã£ãããªã©ã®åé¡ããããŸãã
ããã¯ãã¹ãŠããããŒã«ã«ããã°ã«è¿œå ããããã®ã§ãããäžè¬ã«ãéãå®è¡ãããŠãããã·ã³ã®å¶éãæ®ããŸããã
ãã®ãããªãã®ã ãããã¯ãã¹ãŠäœäžãã®ãŽã«ãŒãã³ã§åé¡ãªãæ©èœããŸãã
PSå€ååŸã§ãèå°è£ã«ããããæ®ãããŠããŸã...
PPS ããããæ®åœ±ãããããªããºãã®åçã