Apache Kafka æ¦è¦ï¼Designï¼å訳ã¾ã¨ã
ããã«ã¡ã¯ãããããï¼ãã¼ã¸å
¨ã¦ã¾ã¨ãçµãã£ãã®ã§ã
æå¾ã«ã¾ã¨ãæ稿ã¨ãã¦æ稿ãã¦ããã¾ãã
å°ããã¼ã¸ã¯ä¸è¨ã§ãã
http://kafka.apache.org/07/design.html
ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
1.ä½æ Kafkaã¯ä½ãããã®ãï¼
å
ã
ã¯LinkedInã®Activity Streamã¨Data Processingããã¤ãã©ã¤ã³å¼ã«ç¹ãããã«éçºããããããã¯ãã
æè¿ã¯TumblrãDataSiftã¨ãã£ãä¼æ¥ã§ã使ç¨ããã¦ããã
ãâãSNSããè¤æ°ã®ãµã¼ãã¹ã®æ
å ±ãçµ±åãããããªã·ã¹ãã ã§ä½¿ããã¦ããããã§ãã
ããã§ããActivity Streamã¨ã¯
Webãã¼ã¸ã§é²è¦§ãæ¤ç´¢ããªã³ã¯è¨å®ãªã©ãè¡ãæ´»åå
¨è¬ãæãã
ãããã®ãã¼ã¿ã¯é常ã®ã·ã¹ãã ãªãã°ããã°ãã¡ã¤ã«ã¨ãã¦åºåããå¾ã§å¥é解æã«ç¨ããããã
ããä¸ã¤è¨èãå®ç¾©ããã
Operational Dataã¯ãµã¼ãã®ããã©ã¼ãã³ã¹ãã¼ã¿ï¼CPUãIOçï¼ãæãã
ãããã®ãã¼ã¿ã®çµ±åã«ã¯æ§ã
ãªã¢ããã¼ããããã
Activity DataãOperational Dataã¯Webãµã¤ãéå¶ã®ä¸ã§é常ã«éè¦ãªãã¼ã¿ã¨ãªãã
ã ãããããããããåé解æããã«ã¯ããã¾ã§ããæ´ç·´ãããã¤ã³ãã©ãå¿
è¦ã
Kafkaã¯ä¸è¨ãéæãããæ´ç·´ããã¤ã³ãã©ãã¨ãã¦éçºãããã
2.Activity Dataï¼Operational Dataã®ã¦ã¼ã¹ã±ã¼ã¹ä¾
å人å ã§å ±æããããã¥ã¼ã¹ãã£ã¼ã
æ票çµæã«ãã£ã¦æé©è§£ããã¼ãã©ã³ãã³ã°ã³ã³ãã¹ã
APIãã¡ã¼ã«åä¿¡æ°ããæ»æãã¹ãã ãæ¤ç¥ããã»ãã¥ãªãã£å¯¾ç
éç¨ç£è¦ï¼ããã·ã¹ãã ããµã¤ãã®ã¬ã¹ãã³ã¹ãæªåãã¦ããªãããæ¤ç¥
ã¬ãã¼ãã£ã³ã°ããããå®è¡ï¼ãã¼ã¿è§£æã«å¿ è¦ãªDWHãHadoopçã¸ã®ãã¼ã¿ãã¼ããå®è¡
3.Activity Stream Dataã®ç¹å¾´
é«è² è·ãªã·ã¹ãã ã®ã¹ããªã¼ã ãã¼ã¿è§£æãè¡ãéã
ãã¼ã¿éã¯æ¢åã·ã¹ãã ã®æ°ååãæ°ç¾åã®ãªã¼ãã¼ã«éããã
ä¸è¨ã®åæã«ã®ä¸ã§ã
ããã¾ã§è¡ããã¦ãããã°ãã¡ã¤ã«åéã¯
ãªãã©ã¤ã³ã®ç¶æ³ã«ããã¦ã¯å³å¯ãã¤ã¹ã±ã¼ã©ãã«ã ã£ãã
ã ãããªã¢ã«ã¿ã¤ã ããã»ãã·ã³ã°ãè¡ãã«ã¯é
ãããä¸ã«ã
éç¨ãè¤éã«ãªãå¾åãããã
対ãã¦ãæ¢åã®ã¡ãã»ã¼ã¸ã³ã°ï¼ãã¥ã¼ã¤ã³ã°ã·ã¹ãã ã¯
ãªã¢ã«ã¿ã¤ã ããã»ãã·ã³ã°ãè¡ãã«ã¯é©ãã¦ãããã
æ°¸ç¶å層ãé
ãé¢ä¿ä¸é常ã«å¤§ããå¦çå¾
ã¡ã®ãã¥ã¼ãæ±ãããã¨ã¨ãªã£ã¦ããã
Hadooopã®ãããªãªãã©ã¤ã³ã·ã¹ãã ã«ãã¼ã¿ãæå
¥ããéã«ãåæ§ã®åé¡ãçºçãã
ããã¾ã§ã¯1æéåä½ãã1æ¥åä½ã®å¦çããæä¾ã§ããªãã£ãã
Kafkaã¯ãããã®é
延ãå¦çå¾
ã¡ãã¥ã¼è¥å¤§åã®åé¡ã解決ããããã«
éçºããããã¥ã¼ã¤ã³ã°ãã©ãããã©ã¼ã ã§ããã
Hadoopã®ãããªãªãã©ã¤ã³ã®ã·ã¹ãã ã
ãªã¢ã«ã¿ã¤ã ããã»ãã·ã³ã°ã®ãããªãªã³ã©ã¤ã³ã·ã¹ãã ã®
両æ¹ã«å¯¾ãã¦åä¸ã®ãã¥ã¼ãç¨ãã¦æ
å ±ã®åéãè¡ãã
4.é©ç¨ä¾
ä¸è¨ã®ç»åãLinkedInã§ä½¿ç¨ããã¦ããæ§æã®æ¦è¦ã¨ãªãã
åä¸ã®Kafkaã¯ã©ã¹ã¿ãè¤æ°ã®ç°ãªããã¼ã¿ã½ã¼ã¹ããåéããã
Activityãã¼ã¿ãæ±ã£ã¦ããã
Kafkaã¯ã©ã¹ã¿ã¯ãªã³ã©ã¤ã³ï¼ãªãã©ã¤ã³ã®ãã¼ã¿å©ç¨è
ã«å¯¾ãã¦åä¸ã®ãã¼ã¿ãã¤ãã©ã¤ã³ãæä¾ããã
ä¸è¨ã®ãããªæ§æã«ããã¦ãKafkaã¯å®Activityã¨éåæå¦çã仲ç«ã¡ãããããã¡ã¨ãã¦åãã¦ããã
ã¾ããKafkaã¯ãããã®å
¨ãã¼ã¿ãå¥ãã¼ã¿ã»ã³ã¿ã¼ã§ä½¿ç¨ããããã«åæããæ©è½ãæä¾ãã¦ããã
Kafkaã¯1ã¯ã©ã¹ã¿ã§ãã¼ã¿ã»ã³ã¿ã¼ãã¾ãããããªæ§æã§ã¯ãªããã
è¤æ°ã®ã¯ã©ã¹ã¿ãæ§ç¯ãããã¨ã§ãã¼ã¿ã»ã³ã¿ã¼éã®ããã¼ãå®ç¾ããã
å®éã®æ§æã¨ãã¦ãã³ãã¼å
ã®Kafkaã¯ã©ã¹ã¿ã¯ã³ãã¼å
ã®Kafkaã¯ã©ã¹ã¿ã®
Consumerã¨ãã¦æ±ãã®ã¿ã§ãããé常ã«ã·ã³ãã«ã
ã¾ããä¸è¨ã®ç¹å¾´ã¯è¤æ°ã®ãã¼ã¿ã»ã³ã¿ã¼ãã
ï¼ãæã«ãã¼ã¿ãéç´å¯è½ã§ãããã¨ã示ãã
ä¸ã®å³ã¯è¤æ°ãã¼ã¿ã»ã³ã¿ã¼éã§ããããã¼ããè£å©ããããã®æ§æä¾ã
ä¸è¨ã®æ§æã«ããã¦ãï¼ã¤ã®Local Kafka Clusteréã®éä¿¡ã¯è¡ãããªãã
ï¼ã¤ã®Local Kafka Clusterã¯ç°ãªããµã¤ãºãç°ãªãæ°ã®ãã¼ããä¿æãããã¨ãåºæ¥ãã
ã¾ããï¼ã¤ã®Kafka Clusterã¯ä»»æã®æ°ã®Source Kafka Clusterã®
ãã¼ã¿ãã³ãã¼ãããã¨ãã§ããã
ãã©ã¼ãªã³ã°ã«ã¤ãã¦ã®è©³ç´°ã¯こちら(別ページ)åç §ã
5.åºæ¬è¨è¨æ¹é
Apache Kafkaã®æã¤è¨è¨æ¹éã¯ä¸è¨ã®éãã
1.Kafkaã¯æ°¸ç¶åããå¿ è¦ãããã¡ãã»ã¼ã¸ãå ±éçã«æ±ãããã«è¨è¨
2.ã¹ã«ã¼ãããããã1ã®ç¹å¾´ãæºãããã¨ãåªå ãã¦è¨è¨
3.ç¶æ ã¯ãããã¥ã¼ãµï¼ããã¼ã«ã§ã¯ãªããã³ã³ã·ã¥ã¼ããæ´æ°
4.Kafkaã¯å®å ¨åæ£åããããã¥ã¼ãµï¼ããã¼ã«ï¼ã³ã³ã·ã¥ã¼ãã¯è¤æ°ãã·ã³ã«åæ£ãããã¨ãåæã¨ããã
6.åºæ¬ã³ã³ã»ãã
Kafkaã§ã¯Messageãåºæ¬ã®éä¿¡åä½ã¨ããã
Messageã¯ãããã¯ã¨ããæ±ãã§ãããã¥ã¼ãµãããµã¼ãï¼ããã¼ã«ã¨ãã¦åä½ï¼ã«éä¿¡ãããã
è¤æ°ã®ã³ã³ã·ã¥ã¼ãããããã¯ãåå¾è¨å®ããå ´åã
å
¨ã³ã³ã·ã¥ã¼ãã«å¯¾ãã¦åã
ã®ã¡ãã»ã¼ã¸ãéä»ãããã
ãããã®ãããã¥ã¼ãµï¼ããã¼ã«ï¼ã³ã³ã·ã¥ã¼ãã¯å¥ãã·ã³ã«åæ£é
ç½®ãããã¨ãã§ãã
è«ççãªã°ã«ã¼ãã³ã°ãæ§æãã¦å調åä½ããã
ä¸è¨ã®åä½ã¯ãããã¥ã¼ãµï¼ããã¼ã«ã«ã¨ã£ã¦ã¯èªç¶ã ãã
ã³ã³ã·ã¥ã¼ãã¯ããã¤ãè¨å®ãå¿
è¦ã¨ãªãã
åã³ã³ã·ã¥ã¼ãã¯ã³ã³ã·ã¥ã¼ãã°ã«ã¼ãã«æå±ãããã¨ã§ã¡ãã»ã¼ã¸ã®åä¿¡ãå¯è½ã¨ãªãã
ãã³ã³ã·ã¥ã¼ãã°ã«âãã«æå±ãã¦ããã³ã³ã·ã¥ã¼ã群ãã«å¯¾ãã¦å
¨ã¡ãã»ã¼ã¸ãé
ä¿¡ãããå½¢ã¨ãªãã
ï¼ã³ã³ã·ã¥ã¼ãã°ã«ã¼ãã«æå±ããã³ã³ã·ã¥ã¼ãã®ãã¡ï¼ã¤ã«é
ä¿¡ã
ã¤ã¾ãã¯ãã³ã³ã·ã¥ã¼ãã°ã«ã¼ãã¨ã¯ã
è¤æ°ã®ããã»ã¹ï¼ãã·ã³ãè«ççã«ï¼ã¤ã®ã³ã³ã·ã¥ã¼ãã¨ãã¦è¦ããä»çµã¿ã¨ãªãã
ãã®ã³ã³ã·ã¥ã¼ãã°ã«ã¼ãã«ãã£ã¦ãã¥ã¼ãJMSãããã¯ã®ãµãã¼ããå¯è½ã
ãã¥ã¼ã¤ã³ã°ããµãã¼ãããéã«ã¯ãè¤æ°ã®ã³ã³ã·ã¥ã¼ããï¼ã³ã³ã·ã¥ã¼ãã°ã«ã¼ãã«æå±ããã
åã¡ãã»ã¼ã¸ãï¼ã¤ã®ã³ã³ã·ã¥ã¼ãã«éä»ããã
JMSãããã¯ããµãã¼ãããéã«ã¯ã
åã³ã³ã·ã¥ã¼ããåã
ã³ã³ã·ã¥ã¼ãã°ã«ã¼ããä¿æããããã«ããã°ã
å
¨ã³ã³ã·ã¥ã¼ãã«å¯¾ãã¦å
¨ã¡ãã»ã¼ã¸ãé
ä¿¡ãããã
ä¸è¬çãªKafkaå©ç¨å½¢æ
ã¨ãã¦ã
è¤æ°ã®ã³ã³ã·ã¥ã¼ãã°ã«ã¼ããæã¡ãåã
ãå
¨ã¡ãã»ã¼ã¸ãåä¿¡ããã±ã¼ã¹ã¨ãªãã
Kafkaã¯ã³ã³ã·ã¥ã¼ãã®æ°ãããã¤ãã£ã¦ãåé¡ãªããã¨ããã
ãã¤ï¼ã¤ã®ã¡ãã»ã¼ã¸ãï¼åããå¦çãã¦ã¯ãããªãã¨ããå¶ç´ããªãå ´åã«é©ããã
7.ã¡ãã»ã¼ã¸ã®æ°¸ç¶åï¼ä¿æ
ãã¡ã¤ã«ã·ã¹ãã ãæãããªï¼
Kafkaã¯ã¡ãã»ã¼ã¸ã®ä¿åã¨ä¿æã«ããã£ã¦ãã¡ã¤ã«ã·ã¹ãã ã«å¯æ¥ã«ä¾åãã¦ããã
ãã£ã¹ã¯ã¯é
ãã¨ããä¸è¬è¦è§£ãããããã
ããæ¸ãã¦ãã¾ãã¨æ§è½ã確ä¿ã§ãããçããããããããªãã
ãã ãå®éã®ã¨ãããã£ã¹ã¯ã¯ã©ã使ããã§å¤§ããããã©ã¼ãã³ã¹ãå¤ããã
ãã£ã¹ã¯ã®æ§é ã«ä½µããè¨å®ãè¡ãã°ããããã¯ã¼ã¯ã¨åçã®æ§è½ãåºããã¨ãå¯è½ã§ããã
ãã£ã¹ã¯æ§è½ã«é¢ãããã¤ã³ãã¯ã
ãã£ã¹ã¯æ§è½ã¯ãã£ã¹ã¯ã®ã·ã¼ã¯ã«ãã£ã¦é
延ãçºçããã¨ãããã¨ã
å®éã®ã¨ãããã·ã¼ã±ã³ã·ã£ã«é åã«å¯¾ããæ¸ãè¾¼ã¿æ§è½ã¯
6å°æ§æã®7200rpmã®SATA-RAID5ãã£ã¹ã¯ã§300MB/secã«ãéããã
ã ããã©ã³ãã æ¸ãè¾¼ã¿ã¯50KB/secã¾ã§è½ã¡è¾¼ãã§ãã¾ãã
å®ã«ã10000åè¿ãå·®ãåºã¦ããã
é£ç¶çã«èªã¿æ¸ãã¯å©ç¨æ¹æ³ã«å¿ãã¦äºæ¸¬å¯è½ã
ããã«ãäºåèªè¾¼ï¼é
延æ¸è¾¼ãé§ä½¿ãã¦è«ççãªå°ããèªè¾¼ï¼æ¸è¾¼ã«
ãã¼ã¸ããã°ããã£ã¹ã¯ã®æ§è½ãå¼ãåºããã¨ãã§ããã
ä¸è¨ã®é¢é£æ
å ±ã¨ãã¦ãä¸è¨ã®æ
å ±ãããã
ã¤ã¾ãã¯ãã·ã¼ã±ã³ã·ã£ã«ãªãã£ã¹ã¯ã«å¯¾ããã¹ã«ã¼ãããã¯ã
ã©ã³ãã ãªã¡ã¢ãªã¢ã¯ã»ã¹ãä¸åãã
ä¸è¨ã«ãããããªæ§è½ã®å·®åãè£ãããã«ã
æè¿ã®ï¼¯ï¼³ã¯ã¡ã¢ãªããã£ã¹ã¯ã®ãã£ãã·ã¥é åã¨ãã¦ç©æ¥µçã«ç¨ãã¦ããã
æè¿ã¯ã©ããªï¼¯ï¼³ã§ãã¡ã¢ãªè§£æ¾ã®ï¼è¥å¹²ã®ï¼æ§è½è² è·ãè¦è¾¼ãã ä¸ã§
空ãã¡ã¢ãªé åãå
¨ã¦ãã£ã¹ã¯ãã£ãã·ã¥ã¨ãã¦è»¢ç¨ãã¦ããã
ãã£ã¹ã¯èªè¾¼ï¼æ¸è¾¼ã¯ä¸è¨ã®ãã£ã¹ã¯ãã£ãã·ã¥ãéãã¦è¡ãããã
ãã®ãããããã»ã¹ãä¿æãã¦ããããã»ã¹å
ãã£ãã·ã¥ã
OSã®ä¿æãã¦ãããã¼ã¸ãã£ãã·ã¥ã¨éè¤ãã¦ããã
çµæãéè¤ããæ¸ãè¾¼ã¿ãè¡ãããç¶æ³ã
ãã¤ã¬ã¯ãIOãç¨ããã«è§£æ¶ãããã¨ã¯å®¹æã§ã¯ãªãã
æ´ã«å¿ãã¦ã¯ãªããªãå
容ã¨ãã¦ãJVMä¸ã®
Javaã®ã¡ã¢ãªå©ç¨ã¨ãã¦ä¸è¨ã®ï¼ã¤ãæ¼ããã¦ããå¿
è¦ãããã
1.ãªãã¸ã§ã¯ãã®ã¡ã¢ãªãªã¼ããããã大ããããã°ãã°éè¤ãã¦ä¿æããã
2.Javaã®GCã¯ãã¼ãä¸ã®ãã¼ã¿ãå¢ããã«ã¤ãã¦ã大éæãã¤è² è·ã¯å¢å¤§ãã
ä¸è¨ã®è¦ç´ ã®çµæã¨ãã¦ã
ãã¼ã¸ãã£ãã·ã¥ã«ä¾åãããã¡ã¤ã«ã·ã¹ãã ã¯
ã¡ã¢ãªãã£ãã·ã¥ãªã©ä»ã®é åã«ä¿æããããåªãããã®ã¨ãªã£ã¦ããã
å
¨ç©ºãã¡ã¢ãªã®å°ãªãã¨ãåã®ãã£ãã·ã¥ãä¿æãããã¨ã§ã
åã
ã®ãªãã¸ã§ã¯ãã«çç®ããããæçµçã«ä¿æãããã¤ãæ°ã¯å°ãããªãã
çµæãã¡ã¢ãªã32GBã®ãã·ã³ä¸ã§28-30GBã®ãã£ãã·ã¥ãGCã®ããã«ãã£ãªãã§æã¤ãã¨ãå¯è½ã¨ãªãã
ï¼ãã®è¾ºãã¾ã訳ãã¦ãã¾ããã
ï¼ã¨ããããããã»ã¹å
ãã£ãã·ã¥ã使ãããç´ ç´ã«OSã®æ©æ§ã使ããã¨ãããã¨ãªã®ã¯ç¢ºãã§ããã
ãã®ä¸ããããã®ãã£ãã·ã¥ã¯ããã»ã¹ãåèµ·åãã¦ãä¿æããã¾ãã
対ãã¦ãããã»ã¹å
ãã£ãã·ã¥ã®å ´åããã»ã¹åèµ·åæã«å度åæåãããã
åæåç¨ãã¼ã¿ãç ´æ£ãã¦ã³ã¼ã«ãèµ·åããå¿
è¦ãããã¾ãã
ï¼ãã£ãã·ã¥åæåã«ã¯10GBã§10åãããã¨ãããã¨ãããå¾ã¾ãã
ãã¾ããã³ã¼ã«ãèµ·åã®å ´ååæã®ããã©ã¼ãã³ã¹ãä½ä¸ãã¾ããï¼
å ãã¦ããã£ãã·ã¥ã¨ãã¡ã¤ã«ã·ã¹ãã ã®åæã
ããã»ã¹ã§ï¼åè¡ãã¨ããå®è£
ã¨æ¯ã¹ã¦ç¢ºå®ã«å®æ½ãããOSã«ãã ããäºã«ãã£ã¦ã
ã³ã¼ããç°¡ç¥åããã¾ãã
ã¾ãããã£ã¹ã¯ä½¿ç¨ãç·å½¢ã¢ã¯ã»ã¹ãå¤ãå ´åã
ãã¼ã¸ãã£ãã·ã¥ã«ããå
èªã¿æ©æ§ãããæå¹ã«ä½ç¨ãã¾ãã
ããã¾ã§è¨è¿°ããè¨è¨ã¯åºæ¥ãéãã¡ã¢ãªä¸ã«ãã¼ã¿ãä¿æãã
å¿
è¦ãªå ´åã®ã¿ãã£ã¹ã¯ã«åºåããã»ã»ã»ã¨ããè¨è¨ã¨æ¯ãã¦é常ã«ã·ã³ãã«ã§ãã
å
¨ã¦ã®ãã¼ã¿ã¯ç¹ã«æ¸ãè¾¼ã¿å½ä»¤ã®å®æ½ç¡ãã«å¸¸ææ°¸ç¶åããã¾ãã
âãå®éã«ã¯OSãå¾ã§æ°¸ç¶åããããã®ãã¡ã¤ã«ãã£ãã·ã¥ã«æ¸ãè¾¼ãã®ã¿ã§ãã
ãã¼ãã¯ã©ãã·ã¥ã«ãã£ã¦æ¶ãããªã¹ã¯ãããç¶æ
ã®ã¡ãã»ã¼ã¸å¢å¤§ãé²ãããã
ä¸å®æéãã¨ï¼ä¸å®æ°ã®ã¡ãã»ã¼ã¸ãä¿æãããã³ã«ç©çãã£ã¹ã¯ã¸ã®æ¸ãè¾¼ã¿ãè¡ã
è¨å®ã®è¿½å ãå¯è½ã¨ãã¦ããã
ãã¼ã¸ãã£ãã·ã¥ä¸å¿ã®ãã®è¨è¨ã¯このページãåèã«ãã¦ã»ããã
ç解ã®æå©ãã¨ãªãã¯ãã ã
ä¸å®ã®æéå ã«æºãããããåãã
ã¡ãã»ã¼ã¸ã³ã°·ã·ã¹ãã ã®ã¡ã¿ãã¼ã¿ã«ä½¿ç¨ãããæ°¸ç¶çãªãã¼ã¿æ§é ã¯ãå¤ãã®å ´åãBtreeã§ããã
Btreeæ§æã¯æãæ±ç¨æ§ã®é«ããã¼ã¿æ§é ãå©ç¨å¯è½ã§ããã
ã¡ãã»ã¼ã¸ã³ã°ã·ã¹ãã ã«ããããã©ã³ã¶ã¯ã·ã§ã³ã¨éãã©ã³ã¶ã¯ã·ã§ã³ã®å¦çãå¹
åºããµãã¼ããããã¨ãå¯è½ã
ä½ããBtreeã®ã¢ã¯ã»ã¹ã«ã¯O(logn)ã®ã³ã¹ãããããã
é常ã§ããã°O(logn)ã®æéã¯å®æ°ã¨ãã¦æ±ããããããã£ã¹ã¯ã使ç¨ããã¨ããã¢ã¯ã»ã¹å½¢æ
ã®å ´åããã¯çã§ã¯ç¡ãã
ãã£ã¹ã¯ãããã¼ã¿ãåå¾ããã«ã¯10ããªç§ç¨ã®æéããããã
ãã¤ï¼ã¤ã®ãã¡ã¤ã«ãã·ã¼ã¯ãã¦ããæä¸ã«å¥ã®ãã¡ã¤ã«ãã·ã¼ã¯ãããã¨ã¯ã§ããªãã
ãããèããã¨ãBtreeã¸ã®ã¢ã¯ã»ã¹ãè¡ãå ´åããã ãã§ãã£ã¹ã¯ã«é«ãè² è·ãããããã¨ã«ã¤ãªããã
ã¹ãã¬ã¼ã¸ã·ã¹ãã ã¯ãç©çãã£ã¹ã¯æä½ã¨ãã£ãã·ã¥æä½ãæ··å¨ãã¦ããããè¦ããæ§è½ã¯å¤§ããå¤åããã
ããã«Btreeã§ã¯åæä½ã«ããªã¼å
¨ä½ãããã¯ãé¿ããããã«é常ã«æ´ç·´ããããã¼ã¸ã¾ãã¯è¡ããã¯ã®å®è£
ãå¿
è¦ã¨ããã
å®éã«å®ç¾ããã«ã¯è¡ããã¯ã«ããªãé«ãã³ã¹ããããããã¾ãã¯ä»ã®å
¨ã¦ã®èªã¿åããç´ååããå¿
è¦ãããã
ãã£ã¹ã¯ã«ä¾åãã¦ä¸è¨ã®ããã¯æ§é ãå®ç¾ããå ´åãã£ã¹ã¯ã®æ§è½åä¸ï¼å¯åº¦åä¸ã享åãããã¨ãã§ããªãã
ç´°åãã®ã¢ã¯ã»ã¹ã大éã«çºçããããã§ããã
Kafkaã®å ´åããã®ã³ã°ã½ãªã¥ã¼ã·ã§ã³ã¨åæ§ã«æ°¸ç¶çãã¥ã¼ã¯ã·ã³ãã«ãªãªã¼ãä¸ã«æ§ç¯ããã¦ãããå¾ãããã¼ã¿ã追å ãããã¨ãå¯è½ã
ãã®æ§é ã¯Btreeãä¿æãããããªè±å¯ãªæ©è½ãæããªã代ããã«ã
ãã£ã¹ã¯ã«ã¢ã¯ã»ã¹ããéã®é度ããã¼ã¿ã®ãµã¤ãºã«ä¾åããªãO(1)ã«ãããã¨ãã§ãããäºãã«ãããã¯ãçºçãããªãã
O(1)ã«ãããã¨ã§ãæ§è½ãå®ãã¼ã¿ãµã¤ãºã¨åé¢ãããã¨ãã§ããã
çµæãä¸è¬çãªSATAã®1TB+ã®ãã£ã¹ã¯å®¹éãæ大éã«æ´»ç¨ãããã¨ãå¯è½ã
8.å¹çãæ大å
Kafkaéçºã«ããã£ã¦ãããä»®å®ã¯ã¡ãã»ã¼ã¸ã®éãé常ã«é«ãã¨ãããã¨ã
ã¾ããå
¨ã¦ã®ã¡ãã»ã¼ã¸ãï¼åãã¾ãã¯è¤æ°åèªã¾ããã¨ä»®å®ãã¦ããã
ãã®ãããKafkaã§ã¯ãã¡ãã»ã¼ã¸ã®æ¶è²»ãã§ã¯ãªãããã¡ãã»ã¼ã¸ã®çæãã«æé©åããæ§é ãåãã
ä¸è¨ãå®ç¾ããããã«ç«ã¡ã¯ã ããé害ã¨ãã¦ãä¸è¨ï¼ç¹ãããã
- 大éã®ãããã¯ã¼ã¯ï¼©ï¼¯
- é度ã®ã¡ã¢ãªä¸ã®ãã¤ãã³ãã¼
ãããã®åé¡ãåæã¨ããããã§å¹çåãå³ãããã
APIã¯Group Messageã« "MessageSet"ã¨ãã¦æ½è±¡åãå ãã¦æ§ç¯ããã¦ããã
ãã®APIæ§æã«ãã£ã¦ãè¤æ°ã®ã¡ãã»ã¼ã¸ãåæã«ãããã¯ã¼ã¯è»¢éãããã¨ãå¯è½ã§ã
ï¼ã¡ãã»ã¼ã¸ãã¨ã«éä¿¡ãçºçããããããããã¯ã¼ã¯ã®ã³ã¹ããæãããã¨ãã§ããã
å°ããã®MessageSetã®å®è£
ã«ããã¦ã¯ãã¤ãé
åã¾ãã¯ãã¡ã¤ã«ãã©ããããé常ã«èãAPIãæä¾ããã
ã¡ãã»ã¼ã¸ã®ã·ãªã¢ã©ã¤ãºï¼ãã·ãªã¢ã©ã¤ãºã¯å¿
è¦ãªå ´åã®ã¿è¡ããããã¤é
延å®è¡ãããã
ï¼å¿
è¦ããªãå ´åãã·ãªã¢ã©ã¤ãºãããªãããã«ãã¦ããï¼
Brokerããã»ã¹ã«ãã£ã¦æ°¸ç¶åãããã¡ãã»ã¼ã¸ãã°ã¯åç´ã«ãã£ã¹ã¯ã«åºåãããMessageSetã®ãã£ã¬ã¯ããªã®ã¿ã
ãã®åç´ãªæ§é ã«ãã£ã¦ãBrokerããã»ã¹ã¨Consumerããã»ã¹ã§åä¸ã®ãã¡ã¤ã«å½¢å¼ãå
±æãããã¨ãå¯è½ã
ï¼ã¾ããProducerããã»ã¹ããåä¿¡ããã¡ãã»ã¼ã¸ãæ¤è¨¼ããä¸ã§è¿½è¨ãããã¨ãå¯è½âï¼ï¼
ãããã®æ°¸ç¶åã¡ãã»ã¼ã¸ã¨ãããã¯ã¼ã¯è»¢éãå
±éãã©ã¼ãããåãããã¨ã§åæä½ã®æé©åãå¯è½ã
UNIXç³»ãªãã¬ã¼ãã£ã³ã°·ã·ã¹ãã ã§ã¯ã½ã±ããã«ãã¼ã¸ãã£ãã·ã¥ãã
ãã¼ã¿ã転éããããã®é«åº¦ã«æé©åãããã³ã¼ããã¹ãæä¾ãã¦ããã
Linuxã§ã¯sendfileã·ã¹ãã ã³ã¼ã«ã使ç¨ãã¦è¡ãããã
Javaã¯FileChannel.transferTo APIã§ãã®ã·ã¹ãã ã³ã¼ã«ãå©ç¨å¯è½ã
sendfileãå©ç¨ãããã¨ã«ããå©ç¹ãç解ããããã«ã¯ã
ã½ã±ãããããã¡ã¤ã«ã¸ã®ãã¼ã¿ã®è»¢éã®ããã®å
±éã®ãã¼ã¿ãã¹ãç解ãããã¨ãéè¦ã§ããã
é常ã®ã¢ããªã±ã¼ã·ã§ã³ã«ããã¦ã¯ãã¡ã¤ã«âã½ã±ããã¸ã®è»¢éã¯ä¸è¨ã®ããã¼ã§è¡ãããã
- ãªãã¬ã¼ãã£ã³ã°ã·ã¹ãã ã¯ãã«ã¼ãã«ç©ºéã§ãã¼ã¸ãã£ãã·ã¥ã«ãã£ã¹ã¯ãããã¼ã¿ãèªã¿åºã
- ã¢ããªã±ã¼ã·ã§ã³ã¯ãã¦ã¼ã¶ç©ºéãããã¡ã«ã«ã¼ãã«ç©ºéãããã¼ã¿ãèªã¿åºã
- ã¢ããªã±ã¼ã·ã§ã³ã¯ãã¦ã¼ã¶ç©ºéãããã¡ããã«ã¼ãã«ç©ºéã«å¯¾ãã¦ãã¼ã¿ãæ¸ãè¾¼ã¿
- ãªãã¬ã¼ãã£ã³ã°ã·ã¹ãã ã¯ã«ã¼ãã«ç©ºéä¸ã®ã½ã±ãããããã¡ããNICãããã¡ã«ãã¼ã¿ãã³ãã¼ãã
ããã¯æããã«éå¹ççã§ããã
4ã¤ã®ã³ãã¼ã2ã¤ã®ã·ã¹ãã ã³ã¼ã«ãæãã§ãã¾ãããã
sendfileãç¨ããã°OSãç´æ¥ãããã¯ã¼ã¯ã«ãã¼ã¸ãã£ãã·ã¥ãããã¼ã¿ãéä¿¡ãããã¨ãã§ããè¤æ°åã®ã³ãã¼ãåé¿ãããã
ãã®æé©åããããã¹ã«å¿
è¦ã¨ãªãã®ã¯NICãããã¡ã«å¯¾ããã³ãã¼ã®ã¿ã¨ãªãã
Kafkaã¯ä¸è¬çãªä½¿ç¨ä¾ã¯ããããã¯ä¸ã«å¯¾ãã¦è¤æ°ã®Consumerãããã¨ä»®å®ãã¦ããã
ä¸è¨ã®ã³ãã¼æé©åã使ç¨ãã¦ããã¼ã¿ã¯ä¸åº¦ã ããã¼ã¸ãã£ãã·ã¥ã«ã³ãã¼ãã¦ããã
é常ã®ã¢ããªã±ã¼ã·ã§ã³ã®ããã«ã¡ã¢ãªã«æ ¼ç´ããè¦æ±ããããã³ã«ã«ã¼ãã«ç©ºéã«ã³ãã¼ãããããã¨ã¯ãªãã
ãã®ãã¨ã«ãã£ã¦ãã¡ãã»ã¼ã¸ããããã¯ã¼ã¯è»¢éé度ã®éçã«è¿ãé度ã§æ¶è²»ããããã¨ãå¯è½ã«ããã
Javaã§sendfileã¨ã¼ãã³ãã¼ãµãã¼ãã®è©³ç´°èæ¯ã«ã¤ãã¦ã¯ã以ä¸ã®è¨äºãåç §ã
- Efficient data transfer through zero copy(IBM developerWorks)
https://www.ibm.com/developerworks/linux/library/j-zerocopy/
9.ã¨ã³ããã¼ã¨ã³ãã®ãããå§ç¸®
å¤ãã®å ´åãããã«ããã¯ã¯CPUã§ã¯ãªããããã¯ã¼ã¯ã«ãªãã
ç¹ã«ãã¼ã¿ã»ã³ã¿ã¼éã§ã¡ãã»ã¼ã¸ã転éããå¿
è¦ããããããã¯ã¼ã¯ãããã¸ãçµãã§ããå ´åã¯ã
ãã¡ãããã¦ã¼ã¶ã¯Kafkaã®ä»å¨ãªãã§ããã¤ã§ãå§ç¸®ãããã¡ãã»ã¼ã¸ãéä¿¡ãããã¨ã¯ã§ãããã
ãã¦ãã¦ãã®å§ç¸®å¹çã¯ã¡ãã»ã¼ã¸ã®ä¸ã®ãã£ã¼ã«ãã®ç¹°ãè¿ãçã®äºæ
ããããæªãã
ï¼JSONã®ãã£ã¼ã«ãå称ãUser Agentã®å¤ãªã©ï¼
å¹ççã«å§ç¸®ãè¡ãããã«ã¯åã
ã®ã¡ãã»ã¼ã¸åä½ã§å§ç¸®ãè¡ãã®ã§ã¯ãªãã
è¤æ°ã®ã¡ãã»ã¼ã¸ãã¾ã¨ãã¦å§ç¸®ãããå¿
è¦ãããã
çæ³çã«ã¯ã¨ã³ããã¼ã¨ã³ãå§ç¸®æ¹å¼ã»ã»ã»
ã¡ãã»ã¼ã¸ã¯Producerããã»ã¹ãéä¿¡ããåã«å§ç¸®ããããµã¼ãã«å§ç¸®ç¶æ
ã§ä¿æãããã
ãã®ä¸ã§åConsumerããã»ã¹ã§è§£åããæ¹å¼ãåãã®ãæã¾ããã
Kafkaã¯å帰çãªMessageSetã«ãã£ã¦ãã®çæ³çãªå§ç¸®æ¹å¼ãå®ç¾ãã¦ããã
ã¡ãã»ã¼ã¸ã¯éä¿¡åã«ã¡ãã»ã¼ã¸ç¾¤ãã¾ã¨ãã¦å§ç¸®ãããã®å¾ç¨ããã¨ãã¾ã§å§ç¸®ç¶æ
ã§ç¶æãããã
Kafkaã§ã¯GZIPã¨Snappyå§ç¸®æ¹å¼ããµãã¼ããã¦ããã
10.ã¡ãã»ã¼ã¸æ¶è²»å´é§åã®ç¶æ 管çæ¹å¼
ã©ã®ã¡ãã»ã¼ã¸ã¾ã§ãæ¶è²»ããããã管çããæ©è½ã¯ã¡ãã»ã¼ã¸ã³ã°ã·ã¹ãã ã®éè¦æ©è½ã®ï¼ã¤ã
ã¾ãããã®ç¶æ
管çæ¹å¼ã¯ç´æçã§ã¯ãªããããããªãããã¡ãã»ã¼ã¸ã³ã°ã·ã¹ãã ã®æ§è½ã«å¤§ããå½±é¿ããã
ç¶æ
管çã¯æ°¸ç¶çãªç¶æ
å¤ï¼ã¤ã¾ãã¯ãã¡ã¤ã«ã«åæï¼ãæ´æ°ããå¿
è¦ããããã©ã³ãã ã¢ã¯ã»ã¹ãçºçããã
çµæãã¹ãã¬ã¼ã¸ã·ã¹ãã ã®ã¹ã«ã¼ãããã§ã¯ãªããã·ã¼ã¯æéã«å½±é¿ãåããå¯è½æ§ãããã
ã»ã¨ãã©ã®ã¡ãã»ã¼ã¸ã³ã°ã·ã¹ãã ã«ããã¦ã¯ããç¶æ
管çãã¯Brokerããã»ã¹ï¼ã¡ãã»ã¼ã¸ãæä¾ããå´ï¼ã管çããã
ã¡ãã»ã¼ã¸æä¾å´ã¯Consumerã«å¯¾ãã¦ã¡ãã»ã¼ã¸ãéä¿¡ããå¾ããã¼ã«ã«ã§ãç¶æ
ãæ´æ°ããã
ããã¯é常ã«åãããããæ¹å¼ã ãããå®éã«ã©ãã«ã¡ãã»ã¼ã¸ãéä¿¡ãããããã«ã¤ãã¦ã¯ããããªãã
å¤ãã®ã¡ãã»ã¼ã¸ã³ã°ã·ã¹ãã ã¯ãã®ç¶æ
管çæ¹å¼ã®ããã«ãã¾ãã¹ã±ã¼ã«ããªãã
ã ããã¡ãã»ã¼ã¸æä¾å´ã¯å¦çãå®äºããã¡ãã»ã¼ã¸ãããåé¤ã§ããããã«ä¿æãããã¼ã¿ã¯å°ããä¿ã¤ãã¨ãã§ããé¢ä¿ä¸ã
é常ã«å®ç¨çãªé¸æã§ããã®ã確ãã
å®ã¯ãã¡ãã»ã¼ã¸æä¾å´ã¨ã¡ãã»ã¼ã¸æ¶è²»å´ã®ã¡ãã»ã¼ã¸æ¶è²»ç¶æ
ã®åæã¯éè¦ãªåé¡ãã¨ããã®ã¯æ£ãããªãã®ãããããªããï¼ï¼ï¼
ããã¡ãã»ã¼ã¸æä¾å´ããããã¯ã¼ã¯ãéãã¦ã¡ãã»ã¼ã¸ãéä¿¡ãããã¨ã«ãã¼ã«ã«ã®ç¶æ
ãæ´æ°ããå ´åã
ã¡ãã»ã¼ã¸æ¶è²»å´ãã¡ãã»ã¼ã¸ã®å¦çã«å¤±æããå ´åãã¡ãã»ã¼ã¸ã¯æ¶å¤±ãã¦ãã¾ãã
ãã®åé¡ã解決ããããã«å¤ãã®ã¡ãã»ã¼ã¸ã³ã°ã·ã¹ãã ã«ããã¦ã¯Ackæ©è½ãæè¼ãã¦ããã
ããã¯ã¡ãã»ã¼ã¸æ¶è²»å´ããããã®ã¡ãã»ã¼ã¸ã«ã¤ãã¦ã¯å¦çãå®äºãããã¨éç¥ãåãããã¨ã§ã
æçµçãªã¡ãã»ã¼ã¸ã®åé¤ãè¡ããã®ã
ããã¾ã§ã¯éä¿¡ããã¡ãã»ã¼ã¸ã«ã¤ãã¦ããã©ã°ãè¨å®ããã ãã§åé¤ã¯è¡ããªãã
ãã®æ¹å¼ã¯ã¡ãã»ã¼ã¸ãæ¶å¤±ããåé¡ã«ã¤ãã¦ã¯å¯¾å¦ã§ããããã¾ãæ°ããªåé¡ãçãã
第ï¼ã®åé¡ã¨ãã¦ã¡ãã»ã¼ã¸æ¶è²»å´ãã¡ãã»ã¼ã¸ãå¦çããããAckãéä¿¡ããåã«å¤±æããå ´åãï¼åã¡ãã»ã¼ã¸ã¯æ¶è²»ãããã
第ï¼ã®åé¡ã¨ãã¦ããã©ã¼ãã³ã¹å¨ãã®åé¡ãããã
ç¾å¨ã¡ãã»ã¼ã¸æä¾å´ã¯ï¼ã¡ãã»ã¼ã¸ã«å¯¾ãã¦è¤æ°ã®ç¶æ
ãä¿æãã¦ãã¾ã£ã¦ããã
ï¼æªå¦çãéä¿¡æ¸æªå®äºï¼åãã¡ãã»ã¼ã¸ãéãæ¶è²»è
ã«éä¿¡ããªãããã«å¿
è¦ãå®äºï¼
ã¾ãããéä¿¡ãããå®äºãã¦ããªãããç¶ç¶ããã¨ããç¶æ
ãã¡ãã»ã¼ã¸æ¶è²»å´ã®ç¶æ
ã«ãã£ã¦ã¯çºçããããã
ãããã®ç¶æ
ã¸ã®å¯¾å¦ãè¡ãå¿
è¦ãããã
ã¡ãã»ã¼ã¸é ä¿¡ã»ãã³ãã£ã¯ã¹
ããã¾ã§ãããããããã«ãã¡ãã»ã¼ã¸é ä¿¡ã®ä¿è¨¼æ¹å¼ã¨ãã¦ä¸è¨ã®ï¼ãã¿ã¼ã³ãèããããã
- ï¼å以ä¸ï¼åè¿°ãã第ï¼ã®ã±ã¼ã¹ãã¡ãã»ã¼ã¸ã¯æä¾å¾ããåé¤ããããçµæãæ¶è²»å´ã®é害ã«ãã£ã¦ã¯å¦çãããªãã¡ãã»ã¼ã¸ãçºçããã
- å°ãªãã¨ãï¼åï¼åè¿°ãã第ï¼ã®ã±ã¼ã¹ãåã¡ãã»ã¼ã¸ã«ã¤ãã¦ï¼åå¦çããããã¨ãä¿è¨¼ããããã失æã®å ´åã¯ï¼å以ä¸é ä¿¡ãããã
- ï¼åº¦ã ãï¼ä½ãããããã«ããããåã¡ãã»ã¼ã¸ã«å¯¾ãã¦ãï¼åã ããé ä¿¡ããããã¨ãä¿è¨¼ãããã±ã¼ã¹
ãããã¯ã¤ã¾ãã¯ããã©ã³ã¶ã¯ã·ã§ã³ã®åé¡ãã®ããªã¨ã¼ã·ã§ã³ã
ï¼ã¾ãã¯ï¼ç¸ã³ããããPaxosã®ããªã¨ã¼ã·ã§ã³ã®ã¢ã«ã´ãªãºã ã«ãã£ã¦ãå³å¯ã«ï¼åã ããå¦çããããã¨ãå¯è½ã
ãã ããããã¤ãã®æ¬ ç¹ãåå¨ããã
ä¸è¨ã®ã¢ã«ã´ãªãºã ãç¨ããå ´åè¤æ°åã®å¾å¾©éä¿¡ãå¿
è¦ã¨ãªãã
ãã¤ç¹ã«æéå¶éãåå¨ããªãã¢ã«ã´ãªãºã ã®ããç¶æ³æ¬¡ç¬¬ã§ã¯å®äºããªãã¾ã¾æ¾ç½®ããããããªãã¨ãããå¾ãã
åæ£åæã¢ã«ã´ãªãºã ã«ã¯ä¸è¨ã®ãããªå¶ç´ãã©ããã¦ãçºçãã¦ããã
Kafkaã§ã¯ãããã®ã¡ã¿ãã¼ã¿ã«å¯¾ãã¦ï¼ã¤çãã対å¦ãè¡ã£ã¦ããã
ï¼ã¤ç®ã¨ãã¦ãã¹ããªã¼ã ï¼ãã¼ã¿ã®æµãï¼ã¯Brokerããã»ã¹ãã¨ã«å
¨ãç°ãªããã¼ãã£ã·ã§ã³ã«åå²ãã¦ããã
ãããã®ãã¼ãã£ã·ã§ã³ã®æå³ã¨ãã¡ãã»ã¼ã¸ãã©ã®ãã¼ãã£ã·ã§ã³ã«éä¿¡ãããã¯Producerããã»ã¹ã«å§ãããã¦ããã
åä¸ãã¼ãã£ã·ã§ã³å
ã®ã¡ãã»ã¼ã¸ã¯Brokerããã»ã¹å
ã§åä¿¡é ã«ã½ã¼ããããåãé ã§Consumerããã»ã¹ã«æä¾ãããã
ããã¯ã¤ã¾ãã¯åã¡ãã»ã¼ã¸ãã¨ã«ç¶æ
管çï¼æ¶è²»ãããããã¾ã ãï¼ãããã®ã§ã¯ãªãã
Consumerããããã¯ããã¼ãã£ã·ã§ã³ãã¨ã«ã®ã¿ç¶æ
管çãããã°ãããã¨ã示ãã¦ããã
ãã®ãããã¡ãã»ã¼ã¸ã®æ¶è²»ç¶æ
ã¯åã
ã®ã¡ãã»ã¼ã¸ã«å¯¾ãã¦ã§ã¯ãªã
Consumerããããã¯ããã¼ãã£ã·ã§ã³ã«ã¤ãã¦ä¿åãããã
ããããªãã»ããã¨å¼ã³ããã®æ©æ§ã®ãããã§Kafkaã¯ã¡ãã»ã¼ã¸ã®æ¶è²»ç¶æ
ã«ã¤ãã¦é常ã«å°ãããã¼ã¿ã§ç®¡çå¯è½ã¨ãªãã
詳細ã«ã¤ãã¦ã¯å®è£
ã»ã¯ã·ã§ã³åç
§ã
ã¡ãã»ã¼ã¸ã®æ¶è²»ç¶æ 管ç
Kafkaã«ããã¦ã¯Consumerå´ã§ã¡ãã»ã¼ã¸ãã©ãã¾ã§æ¶è²»ãããã®ç¶æ
ï¼ãªãã»ããï¼ãç¶æããå¿
è¦ãããã
Kafkaã®Consumerã©ã¤ãã©ãªã¯åºæ¬èªåãã©ãã¾ã§ã¡ãã»ã¼ã¸ãå¦çãããã®ãç¶æ
å¤ããZookeeperã«æ¸ãè¾¼ãã
ããããªãããç¶æ
å¤ãConsumerãå¦ççµæãæ¸ãè¾¼ããã¼ã¿ã¹ãã¢ã¨åããã¼ã¿ã¹ãã¢ã«æ¸ãè¾¼ããã¨ãæçãããããªãã
ä¾ãã°ãConsumerã¯ããã¤ãã®éè¨å¤ãéä¸åã®ãã©ã³ã¶ã¯ã·ã§ãã«OLTPãã¼ã¿ãã¼ã¹ã«å
¥åãããã¨ãã§ããã
ãã®ã±ã¼ã¹ã«ããã¦ã¯Consumerã¯ã©ãã¾ã§ã¡ãã»ã¼ã¸ãå¦çãããã®ç¶æ
ããã¼ã¿ãã¼ã¹æ´æ°ã¨åãã©ã³ã¶ã¯ã·ã§ã³ã¨ãã¦åæ ãããã¨ãã§ããã
åãã©ã³ã¶ã¯ã·ã§ã³ã§å®æ½ãããã¨ã«ããåæ£é¨åããªããªããåæ£åæåé¡ãããããçºçãããªããããã¨ã«ã¤ãªããã
é¡ä¼¼ã®å¯¾å¦ã¯ãã©ã³ã¶ã¯ã·ã§ãã«ã§ã¯ç¡ããã¼ã¿ã¹ãã¢ã«ããã¦ãè¯å¥½ã«åä½ããã
æ¤ç´¢ã·ã¹ãã ã¯ã¡ãã»ã¼ã¸ã®å¦çç¶æ
ãæ¤ç´¢ã¤ã³ããã¯ã¹ã¨å
±ã«ä¿åãããã¨ãã§ããã
ããã¯èä¹
æ§ã®ä¿è¨¼ãæä¾ããªãå ´åãããããã©ããã¡ãã»ã¼ã¸ã®ãªãã»ããã¨æ¤ç´¢ã¤ã³ããã¯ã¹ãåæããã¦ããã
ãã®ãããæ¤ç´¢ã¤ã³ããã¯ã¹ãåºåããå ´åã«ã¯ã©ãã·ã¥ãã¦æ¶ããå ´åã
ãæ¤ç´¢ã¤ã³ããã¯ã¹åºååã®ãªãã»ãããããéå§å¯è½ãªãããä¿åããææ°ã®ç¶æ
ããåéãããã¨ãå¯è½ã
åæ§ã«ãHadoopã§Kafkaããã®ãã©ã¬ã«ãã¼ããå®è¡ãã¦ããå½ç¤¾ã®ã·ã¹ãã ã«ããã¦ã¯
ä¼¼ããããªç¶æ
åæã¨å¾©æ§ãè¡ããã¨ãå¯è½ã
åã
ã®ãããã¼ã¯ãããã¿ã¹ã¯ã®çµäºæã«HDFSã¸ã®æå¾ã®æ¶è²»ã¡ãã»ã¼ã¸ã®ãªãã»ãããæ¸ãè¾¼ãã
HDFSã«æ ¼ç´ããããªãã»ããããã¸ã§ãã失æãã¦åèµ·åãããå ´åãåãããã¼ã¯åã«åèµ·åããã°ããã
ãã®è¨è¨æ¹éãåã£ããã¨ã«ãããå¯æ¬¡çãªå©ç¹ãçãã¦ããã
Consumerã¯ãªãã»ãããå¤ãå¤ã«å·»ãæ»ããã¨ã«ãããåã®ç¶æ
ããå度ãã¼ã¿ãæ¶è²»ãããã¨ãå¯è½ã
ããã«ãããä¸è¬çãªãã¥ã¼ã®æ¦å¿µã¨ã¯ç°ãªãããæ¶è²»è
ãµã¤ãããè¦ãã¨é½åãããåä½ãå®ç¾å¯è½ã
ä¾ãã°ãæ¶è²»ããå´ã®ã³ã¼ãã«ãã°ããããã¡ãã»ã¼ã¸ãå¦çããå¾ã«ãã°ãä¿®æ£ãããå ´åã
ãã°ãçºç¾ããåã®ãªãã»ããããåã¹ã¿ã¼ããããã¨ã«ããã¡ãã»ã¼ã¸ãåå¦çããããã¨ãå¯è½ã
ããã·ã¥å¯¾ãã«
ããã¾ã§ã®BrokerãConsumerå´ã®è©±ã«é¢é£ãã質åã¨ãã¦ã
Brokerå´ããã¼ã¿ãpushããã®ããConsumerå´ãã¡ãã»ã¼ã¸ãpullããã®ãããããã
Kafkaã¯ãã¼ã¿ã®æµãã¨ãã¦ä¸è¨ã®ãããªãã¶ã¤ã³ãåã£ã¦ããã
- ProducerâBrokerã«ãã¼ã¿ãpush
- BrokerâConsumerã«ãã¼ã¿ãpull
æè¿ã®Scribeãflumeçã®ã·ã¹ãã ã«ããã¦ã¯ãã°åéã«ç¦ç¹ãå½ã¦ã
åãã¼ããBrokerã¨ãã¦åä½ãããã¼ã¿ãpushããã¢ããã¼ããåã£ã¦ããã
ããããªãããPushãã¼ã¹ã®ã·ã¹ãã ã«ããã¦ã¯Brokerå´ã¯Consumerå´ã§è»¢éé度ãå¶éããããããª
å¤å½©ãªæ¶è²»ã¢ãã«ã«å¯¾å¿ããã®ã¯å°é£ã«ãªãã
Kafkaã®ç½®ãã´ã¼ã«ã¨ãã¦ã¯ãæ¶è²»è
å´ã§å¯è½ãªéãæ大ã®ã¬ã¼ãã§ã¡ãã»ã¼ã¸æ¶è²»ãå¯è½ã«ããã¨ãããã®ã
ã ããæ®å¿µãªããpushã¢ãã«ã®ã·ã¹ãã ã«ããã¦ã¯æä¾è
å´ãæ¶è²»è
å´ã§ã®æ大å¹çãéæãããã¨ããçµæã
æ¶è²»è
å´ã§å¦çå¯è½ãªé以ä¸ã®ã¡ãã»ã¼ã¸ãéä¿¡ãã¦ãã¾ããã¡ãã»ã¼ã¸ãéå°ã¨ãªãå¾åãããã
æ¶è²»è
å´ã§ãµã¼ãã¹åæ¢ãªã©ã®åé¡ãçºçããå ´åãããã¯ãã容æã«çºçããã
pullãã¼ã¹ã®ã·ã¹ãã ã«ããã¦ã¯ãã®ãã¼ã¹ãæ¶è²»è
å´ã§å¶å¾¡ã§ããããã
ä¸æçã«å¦çé度ãä½ä¸ããå ´åã§ãã£ã¦ãå¾ãã追ãä»ããã¨ãå¯è½ã
ããã¯pushãã¼ã¹ã®ã·ã¹ãã ã«ããã¦æ¶è²»è
å´ãç¶æ³ãéç¥ããããã·ã³ãã«ãªã¢ãã«ã«ä»ä¸ãããã
Kafkaã«ããã¦ã¯pullãã¼ã¹ã®ã·ã¹ãã ã¢ãã«ãåããã¨ã¨ãã¦ããã
11.ã·ã¹ãã ã®åæ£
Kafkaã¯åºæ¬çã«ã¯ã¯ã©ã¹ã¿å
¨ä½ã«åæ£å®è¡ãããã¢ãã«ãåã£ã¦ããããã¹ã¿ã¼ãã¼ãã¨å¼ã°ããåå¨ã¯ãªãã
Brokerããã»ã¹ããäºãã«ï¼å¯¾ï¼ã§å¯¾å¿ãã¦ãããè¨å®ã®æåæ´æ°ãªãã«ãã¼ãã®è¿½å åé¤ãè¡ããã¨ãã§ããã
åæ§ã«ãProducerããã»ã¹ã¨Consumerããã»ã¹ãåçã«èµ·åãããã¨ãå¯è½ã
åBrokerããã»ã¹ã¯Zookeeperã«ã¡ã¿ãã¼ã¿ï¼å©ç¨å¯è½ãªãããã¯æ
å ±ãªã©ï¼ãç»é²ããã
Producerããã»ã¹ã¨Consumerããã»ã¹ã¯Zookeeperã«ç»é²ãããã¡ã¿ãã¼ã¿ãå
ã«
ãããã¯ãçºè¦ãããã¡ãã»ã¼ã¸ã®çæï¼æ¶è²»ã®å調ãè¡ããã¨ãå¯è½ã
12.Producer
Producerããã»ã¹ã®èªåãã¼ããã©ã³ã·ã³ã°
Kafkaã¯ãProducerã®TCPæ¥ç¶ã®ãã©ã³ã¹ãã¨ãããã®å°ç¨ãã¼ããã©ã³ãµã使ç¨ããããã«
ã¯ã©ã¤ã¢ã³ããµã¤ãã®ãã¼ããã©ã³ã·ã³ã°ããµãã¼ããã¦ããã
å°ç¨ã®ã¬ã¤ã¤4ãã¼ããã©ã³ãµã¯Brokerããã»ã¹çµç±ã§TCPæ¥ç¶ã®ãã©ã³ã¹ãåããã¨ã«ãã£ã¦åä½ããã
ãã®æ§æã®å ´åãProducerããã»ã¹ãçç£ããã¡ãã»ã¼ã¸ã¯å
¨ã¦åä¸ã®Brokerããã»ã¹ã«éç´ãããã
ã¬ã¤ã¤4ãã¼ããã©ã³ãµã使ãå©ç¹ã¯åProducerããã»ã¹ã¯åä¸ã®TCPã³ãã¯ã·ã§ã³ã®ã¿ãå¿
è¦ã¨ãã
Zookeeperã¸ã®æ¥ç¶ãè¡ãå¿
è¦ããªããã¨ã§ããã
æ¬ ç¹ã¯ãã¼ããã©ã³ã·ã³ã°ãTCPæ¥ç¶ã¬ãã«ã§è¡ããã¦ãããçµæã¨ãã¦ä¸æããã©ã³ã·ã³ã°ãè¡ãããªããããããªãç¹ã
ããããã¤ãã®Producerããã»ã¹ãä»ã®ãã®ããå¤ãã®ã¡ãã»ã¼ã¸ãçæããå ´åã
ã³ãã¯ã·ã§ã³ãåçã«ã¯ã£ãã¨ãã¦ãåçã«ã¡ãã»ã¼ã¸ãå²ãæ¯ãããããã§ã¯ãªããªãã
ã¯ã©ã¤ã¢ã³ããµã¤ãã®Zookeeperãã¼ã¹ã®ãã¼ããã©ã³ã·ã³ã°ã¯ããããã®åé¡ã®ããã¤ãã解決ããã
Zookeeperãã¼ã¹ã®ãã¼ããã©ã³ã·ã³ã°ã¯Producerããã»ã¹ã«å¯¾ãã¦ä¸è¨ï¼æ©è½ãæä¾ããã
- åçãªBrokerããã»ã¹çºè¦
- ãªã¯ã¨ã¹ãæ¯ã®ãã¼ããã©ã³ã·ã³ã°
åæ§ã«ãZookeeperãã¼ã¹ã®ãã¼ããã©ã³ã·ã³ã°ã¯Producerããã»ã¹ã«å¯¾ãã¦
åãªãã©ã³ãã ã§ã¯ç¡ãã¡ãã»ã¼ã¸ã®IDãå©ç¨ããã¦ã¼ã¶IDã«å¿ãããã©ã³ã·ã³ã°ãå¯è½ã«ããã
ãã®æ©è½ããã»ãã³ãã£ãã¯ãã¼ãã£ã·ã§ãã³ã°ãã¨å¼ã°ããã
以ä¸ã§ãã詳細ã«èª¬æããã
Zookeeperãã¼ã¹ã®ãã¼ããã©ã³ã·ã³ã°ã®åä½ã¯ä¸è¨ã®éãã
ZookeeperWatherã¯ä¸è¨ã®ã¤ãã³ãã«å¯¾ãã¦ã³ã¼ã«ããã¯ãåãåããã¨ãã§ããã
- æ°è¦Brokerããã»ã¹è¿½å
- Brokerããã»ã¹ããã¦ã³
- æ°è¦ãããã¯ã®è¿½å
- Brokerããã»ã¹ãæ¢åãããã¯ã«å¯¾ãã¦ç»é²
å
é¨çã«ã¯Producerããã»ã¹ã¯Brokerããã»ã¹ã¸ã®æ¥ç¶ãã¼ã«ãBrokerããã»ã¹æ¯ã«ä¿æããã
ãã®æ¥ç¶ãã¼ã«ã¯Zookeeperããã®ã³ã¼ã«ããã¯ãåãã
å
¨ã¦ã®çåBrokerããã»ã¹ã¸ã®æ¥ç¶ã®ç¢ºç«ï¼ç¶æãè¡ã£ã¦ããã
ç¹å®ã®ãããã¯ã®ãããã¥ã¼ãµã¼è¦æ±ãæ¥ãã¨ãã«ãBrokerãã¼ãã£ã·ã§ã³ã¯ãã¼ãã£ã·ã§ãã§é¸æãããã
ï¼è©³ç´°ã¯ã»ãã³ãã£ãã¯ãã¼ãã£ã·ã§ãã³ã°ã®ã»ã¯ã·ã§ã³ãåç
§ï¼
ãã¼ã«ããåå¾ããBrokerã¸ã®æ¥ç¶ãªãã¸ã§ã¯ããç¨ãã¦é¸æããBrokerãã¼ãã£ã·ã§ã³ã¸ã®ãã¼ã¿éä¿¡ãè¡ã£ã¦ããã
éåæéä¿¡
éåæãã³ããããã³ã°æä½ã¯ã¡ãã»ã¼ã¸ã³ã°ã·ã¹ãã ãã¹ã±ã¼ã«ãããããã®åºæ¬ã®è¦ç´ ã
Kafkaã§ã¯Producerããã»ã¹ãã¡ãã»ã¼ã¸ãçç£ããéã«éåæãªã¯ã¨ã¹ããã£ã¹ããããªãã·ã§ã³ãæå®å¯è½ã
ããã¯ä¸å®æéãã¨ãã¾ãã¯ä¸å®ãµã¤ãºãã¨ãäºåã«è¨å®ããProducerããã»ã¹å
ã®ã¡ã¢ãªãã¥ã¼ã«ãããã¡ãªã³ã°ããè¦æ±ãã¾ã¨ãã¦éä»ãããã®ã
ãã¼ã¿ã®çæã¬ã¼ãã¯é常ãã¼ããã¨ã«ç°ãªããããéåæãªãã·ã§ã³ãæå®ãããã¨ã§
ãããã¯ã¼ã¯å
ã®ãã©ãã£ãã¯ã軽æ¸ï¼å¹ççãªå©ç¨ãå¯è½ã«ããBrokerããã»ã¹ã¸ã®ãªã¯ã¨ã¹ãè² è·ãä¸å®ã«ããã®ã«å½¹ç«ã¤ã
ã»ãã³ãã£ãã¯ãã¼ãã£ã·ã§ãã³ã°
åã¡ã³ãã¼ã®ãããã¡ã¤ã«ã«å¯¾ãã訪åè
æ°ãç¶æãããã¢ããªã±ã¼ã·ã§ã³ãèããã¨ããã
ãã®å ´åãããã¡ã³ãã¼ã®ãããã¡ã¤ã«ã«å¯¾ãã訪åå±¥æ´ã¤ãã³ãã¯åºæ¥ãã°åããã¼ãã£ã·ã§ã³ãåãConsumerã¹ã¬ããã«ããã¦å¦çãããã¨èããã
Kafkaã®Producerããã»ã¹ã¯çåä¸ã®Kafkaãã¼ããããã³ãã¼ãã£ã·ã§ã³ã¸ã¡ãã»ã¼ã¸ããããã³ã°ãããæ©è½ãæã£ã¦ããã
ã¡ãã»ã¼ã¸ä¸ã®ããã¤ãã®å¤ãå
ã«Brokerããã»ã¹éã«å¯¾ãã¦ã¹ããªã¼ã ãåå²ããæ©è½ã»ã»ã¨ããå½¢ã§å®ç¾ãããã
ãã®ãã¼ãã£ã·ã§ãã³ã°æ©è½ã¯kafka.producer.Partitionerã¤ã³ã¿ãã§ã¼ã¹ãç¶æ¿ãããã¼ãã£ã·ã§ãã¼ãä½æãããã¨ã§
ã«ã¹ã¿ãã¤ãºå¯è½ãããã©ã«ãã§ã¯ã©ã³ãã ã§ãã¼ãã£ã·ã§ãã³ã°ãè¡ãããã
å°ãä¸è¨ã®ä¾ã«ããã¦ã¯ãã¼ãã£ã·ã§ãã³ã°ãè¡ããã¼ã¯MEMBER_IDã«ãªãã
ãã¼ãã£ã·ã§ãã¼ã¯ Hash(MEMBER_ID) % num_partitions ã§é
ä¿¡å
ã®Brokerããã»ã¹ãç®åºããã ããã
13.Hadoopãã®ä»ã®ããããã¼ã¿ãã¼ãã®ãµãã¼ã
Kafkaã¯ã¹ã±ã¼ã©ãã«ãªæ°¸ç¶æ§ãä¿æãã¦ããããããããã·ã¹ãã ã®ããã«
å®æçã«ãã¼ã¿ããã¼ããããã¨ãå¯è½ã
LinkedInï¼ï¼ï¼ã§ã¯Hadoopã¯ã©ã¹ã¿ã¨DWHã«ãã¼ã¿ããã¼ãããããã«ä½¿ç¨ãã¦ããã
ãããå¦çã¯ãã¼ã¿ãã¼ããã§ã¼ãºã¨ãé循ç°ã°ã©ãçãªå¦çããã¼ãå®è¡ãã¦ãã¼ã¿ãåºåãããã§ã¼ãºã¨
段éçã«å®è¡ãããã
ãã®ã¢ãã«ããµãã¼ãããéã«Kafkaã®ããæç¹ããã®ãã¼ã¿ãã¼ããå度å®æ½ã§ããã¨ããç¹é·ã¯
é害ãçºçããéã«é½åãããè¦ç´ ã¨ãªã£ã¦ããã
Hadoopã®ã±ã¼ã¹ã«ããã¦ãKafkaã¯åãã¼ãï¼ãããã¯ï¼ãã¼ãã£ã·ã§ã³åä½ã§ãã¼ã¿ãåå²é
åå¯è½ãªããã
åMapperã¿ã¹ã¯ã«å¯¾ãã¦ãã¼ã¿ãã¼ãè² è·ãåçã«é
åå¯è½ã
Hadoopã¯Taskã®å®è¡ç®¡çãæä¾ããããKafkaãå©ç¨ãããã¨ã§éè¤ãã¼ã¿ã®ãã¼ãã®å±éºãªãã«åèµ·åãå¯è½ã
14.Producerã®API
Producerå´ã®APIã¯ä»¥ä¸ã®ï¼ã¤ã®ä½ã¬ãã«APIãã©ãããã¦ããã
- kafka.producer.SyncProducer
- kafka.producer.async.AsyncProducer
class Producer { /* Sends the data, partitioned by key to the topic using either the */ /* synchronous or the asynchronous producer */ public void send(kafka.javaapi.producer.ProducerData producerData); /* Sends a list of data, partitioned by key to the topic using either */ /* the synchronous or the asynchronous producer */ public void send(java.util.List<kafka.javaapi.producer.ProducerData> producerData); /* Closes the producer and cleans up */ public void close(); }
ãã®APIã¨ããç®çã¯ãã¯ã©ã¤ã¢ã³ãã¸ã®åä¸ã®APIãä»ãã¦ãã¹ã¦ã®çç£æ©è½ãå
¬éãããã¨ã
æ°ããProducerãä½æããéã«ã¯ä¸è¨ã®APIãè¨è¿°ããå¿
è¦ãããã
1.è¤æ°ã®ãããã¥ã¼ãµã¼ã®è¦æ±ããããã¡ãªã³ã°ãã¦éåæãã£ã¹ãããï¼ãã¥ã¼ã¤ã³ã°ãè¡ãAPI
kafka.producer.Producerã¯(producer.type=async)ã¨è¨å®ãããã¨ã§
ã·ãªã¢ã©ã¤ãºï¼Brokerããã»ã¹ã«å¯¾ãã¦é
åããåã«è¤æ°ã®ãªã¯ã¨ã¹ãããããåããæ©è½ãæä¾ããã
ãããã®ãµã¤ãºã¯ãããã¤ãã®è¨å®ãã©ã¡ã¼ã¿ã«ãã£ã¦å¶å¾¡ãããã¨ãã§ããã
ã¤ãã³ãããã¥ã¼ã«å
¥ã£ãå ´åããqueue.timeããbatch.sizeãã®ã©ã¡ããã«éããã¾ã§ãã¥ã¼ã§ãããã¡ãªã³ã°ãããã
ãããã¡ãªã³ã°ãããã¼ã¿ãå¦çããå ´åã
ããã¯ã°ã©ã¦ã³ãã¹ã¬ããï¼kafka.producer.async.ProducerSendThreadï¼ããã¥ã¼ãããã¼ã¿ãåå¾ãã
ã¤ãã³ããã³ãã©ï¼kafka.producer.EventHandlerï¼ããã¼ã¿ã®ã·ãªã¢ã©ã¤ãºã¨é©åãªBrokerããã»ã¹ã¸ã®éä¿¡ãè¡ãã
ã«ã¹ã¿ã ã®ã¤ãã³ããã³ãã©ãevent.handlerã®è¨å®å¤ã«ã¦ãã©ã°ã¤ã³æ¹å¼ã§è¿½å ãããã¨ãå¯è½ã
ãã®å¦çã®æµããProduerãã¤ãã©ã¤ã³ã¨å¼ã³ãåãã§ã¼ãºã«ã³ã¼ã«ããã¯ããã°åºåã
ãã¬ã¼ã¹ç¨ã®ã¡ããªã¯ã¹æ
å ±åéãªã©ã®å¦çããã©ã°ã¤ã³æ¹å¼ã§è¿½å ãã追å ãããã¨ãå¯è½ã
ãããã®å¦ç㯠kafka.producer.async.CallbackHandler ãç¶æ¿ããã¯ã©ã¹ã
è¨å®å¤ãcallback.handlerãã«è¨å®ãããã¨ã§è¿½å å¯è½ã
2.ã¨ã³ã³ã¼ãã®æå®
ã¦ã¼ã¶å´ã§ä¸è¨ã®ã¤ã³ã¿ãã§ã¼ã¹ãç¶æ¿ããã¨ã³ã³ã¼ããæå®ããã
interface Encoder<T> { public Message toMessage(T data); }
ããã©ã«ãã§ã¯ä½ãå®æ½ããªããkafka.serializer.DefaultEncoderãã¯ã©ã¹ã使ç¨ãããã
3.Zookeeperãã¼ã¹ã®èªåBrokerããã»ã¹æ¤ç¥
Zookeeperãã¼ã¹ã®èªåBrokerããã»ã¹æ¤ç¥ããã¼ããã©ã³ã·ã³ã°ã¯Zookeeperã¸ã®æ¥ç¶URLã
è¨å®å¤ãzk.connectãã«è¨å®ãããã¨ã§ä½¿ç¨å¯è½ã
ãã ãããã¤ãã®ã¦ã¼ã¹ã±ã¼ã¹ã«ããã¦ã¯Zookeeperã¸ã®ä¾åãä¸é©åã¨ãªãã±ã¼ã¹ãããã
ãã®å ´åã¯Producerå´ã®ãbroker.listãã«éçãªBrokerãªã¹ããå®ç¾©ããå½¢ã§å¯¾å¿å¯è½ã
ãã®è¨å®ãè¡ã£ãå ´åãProducerè¦æ±ã¯ã©ã³ãã Brokerãã¼ãã£ã·ã§ã³ã«é
åãããã
ããéä¿¡æã«å¯¾è±¡ã®Brokerããã¦ã³ãã¦ããå ´åããã®Producerãªã¯ã¨ã¹ãã¯å¤±æããã
4.å¿ è¦ã«å¿ãã¦ãã¼ãã£ã·ã§ãã¼ãå®ç¾©
ã«ã¼ãã£ã³ã°ã¯ä¸è¨ã®ã¤ã³ã¿ãã§ã¼ã¹ãç¶æ¿ããã¯ã©ã¹ãå®ç¾©ãããã¨ã§å®ç¾å¯è½ã
interface Partitioner<T> { int partition(T key, int numPartitions); }
ãã®APIã¯ãã¼ã¨ãã¼ãã£ã·ã§ã³æ°ã渡ãã¦é
åå
ã®ãã¼ãã£ã·ã§ã³IDãåå¾ããæ§æã«ãªã£ã¦ããã
ãã®IDã¯Producerãªã¯ã¨ã¹ãã«å¯¾ãã¦Brokerãã¼ãã£ã·ã§ã³ãé¸æããbroker_idsã¨
ãã¼ãã£ã·ã§ã³ãªã¹ãã¸ã®ã¤ã³ããã¯ã¹ã¨ãã¦ä½¿ç¨ãããã
ããã©ã«ãã®ãã¼ãã£ã·ã§ãã¼ã¯ãã¼ã®ããã·ã¥å¤ãnumPartitionsã§å°ä½ãåããã¨ã§é
åãè¡ãã
ãã¼ãnullã®å ´åã©ã³ãã Brokerãã¼ãã£ã·ã§ã³ã§é
åãè¡ãã
ã«ã¹ã¿ã ãã¼ãã£ã·ã§ãã¼ã¯è¨å®å¤ãpartitioner.classãã§å®ç¾©ãå¯è½ã
15.Consumerã®API
Kafkaã§ã¯Consumerã®APIã¨ãã¦2ã¬ãã«ã®APIãä¿æãã¦ããã
ä½ã¬ãã«ã® "Simple" APIã¯ãåä¸ã®Brokerããã»ã¹ã¸ã®æ¥ç¶ãç¶æãã
ãµã¼ãã«éä¿¡ããããããã¯ã¼ã¯è¦æ±ã«å¯æ¥ãªå¯¾å¿ãæãã¦ããã
é«ã¬ãã«ã®APIã¯ConsumerããBrokerããã»ã¹ã®è©³ç´°ãé ããèå¾ã®ãããã¯ã¼ã¯ãããã¸çãæ°ã«ãããã¨ãªã
ã¡ãã»ã¼ã¸ãåå¾ãããã¨ãå¯è½ã¨ãªãã
ã¾ããèªåçã«Consumerå´ã®ãªãã»ãããè¨å®ããã
å ãã¦ãé«ã¬ãã«APIã¯ãã©ãã¯ãªã¹ãï¼ãã¯ã¤ããªã¹ãæ¹å¼ï¼æ£è¦è¡¨ç¾ã使ç¨å¯è½ï¼ã§ã¡ãã»ã¼ã¸ããã£ã«ã¿ãªã³ã°ãã¦è³¼èªãããã¨ãå¯è½ã
ä½ã¬ãã«APIã®æ§æã¯ä¸è¨ã®éãã
class SimpleConsumer { /* Send fetch request to a broker and get back a set of messages. */ public ByteBufferMessageSet fetch(FetchRequest request); /* Send a list of fetch requests to a broker and get back a response set. */ public MultiFetchResponse multifetch(List<FetchRequest> fetches); /** * Get a list of valid offsets (up to maxSize) before the given time. * The result is a list of offsets, in descending order. * @param time: time in millisecs, * if set to OffsetRequest$.MODULE$.LATIEST_TIME(), get from the latest offset available. * if set to OffsetRequest$.MODULE$.EARLIEST_TIME(), get from the earliest offset available. */ public long[] getOffsetsBefore(String topic, int partition, long time, int maxNumOffsets); }
ä½ã¬ãã«APIã¯é«ã¬ãã«APIãæ§æããããã«ä½¿ç¨ãããã ãã§ãªãã
HadoopåãConsumerçã®ããã«ç¶æ
管çãä¸é¨ç¹æ®ã¨ãªãConsumerã®æ§æã«ã使ç¨ããã¦ããã
é«ã¬ãã«APIã®æ§æã¯ä¸è¨ã®éãã
/* create a connection to the cluster */ ConsumerConnector connector = Consumer.create(consumerConfig); interface ConsumerConnector { /** * This method is used to get a list of KafkaStreams, which are iterators over * MessageAndMetadata objects from which you can obtain messages and their * associated metadata (currently only topic). * Input: a map of <topic, #streams> * Output: a map of <topic, list of message streams> */ public Map<String,List<KafkaStream>> createMessageStreams(Map<String,Int> topicCountMap); /** * You can also obtain a list of KafkaStreams, that iterate over messages * from topics that match a TopicFilter. (A TopicFilter encapsulates a * whitelist or a blacklist which is a standard Java regex.) */ public List<KafkaStream> createMessageStreamsByFilter( TopicFilter topicFilter, int numStreams); /* Commit the offsets of all messages consumed so far. */ public commitOffsets() /* Shut down the connector */ public shutdown() }
ãã®APIã¯KafkaStreamã¯ã©ã¹ãã¤ãã¬ã¼ã¿ã§æããå½¢ã§å®ç¾ãã¦ããã
åKafkaStreamã¯ã1ãnåã®ãµã¼ãä¸ã®1ãnåã®ãã¼ãã£ã·ã§ã³ããã®ã¡ãã»ã¼ã¸ã¹ããªã¼ã ã表ãã
ãããã£ã¦ãåKafkaStreamã¯è¤æ°ãã¼ãã£ã·ã§ã³ããã®ãã¼ã¿ãæãã¦åä¿¡ãããã¨ãã§ãããã
1ãã¼ãã£ã·ã§ã³ããéä¿¡ããããã¼ã¿ã¯1Streamãªãã¸ã§ã¯ãã«ã®ã¿éãããã
åKafkaStreamã¯ã·ã³ã°ã«ã¹ã¬ããå¦çã®ããã«ä½¿ç¨ãããã
ã¯ã©ã¤ã¢ã³ãã¯ä»»æã«ã¹ããªã¼ã ãä½æãããã¨ãå¯è½ã
createMessageStreamsã¡ã½ãããå¼ã³åºããã¨ã«ãããConsumerããããã¯ã«å¯¾ãã¦ç»é²ããã
çµæãConsumer/Brokeréã§ã®ãªãã©ã³ã¹ãèµ°ããã¨ã«ãªãã
APIå´ã§ã¯ãªãã©ã³ã¹ãæå°éã«ããããã«createMessageStreamsã¡ã½ããå®è¡æã«
è¤æ°ã®ãããã¯ã«å¯¾ããStreamãçæãããã¨ãæ¨å¥¨ãã¦ããã
createMessageStreamsByFilterã¡ã½ããã¯ãã£ã«ã¿ã«ä¸è´ãããããã¯ãçºè¦ããWatcherãªãã¸ã§ã¯ããç»é²ããã
ãã£ã«ã¿ã§è¤æ°ãããã¯ã許容ããå ´åãcreateMessageStreamsByFilterãè¿ãè¤æ°ãããã¯ãè¿ãã¡ãã»ã¼ã¸ã¯
ãå復ããã±ã¼ã¹ããããã¨ãããã¨ã«æ³¨æãããã¨ã
16.ãããã¯ã¼ã¯å±¤
ãããã¯ã¼ã¯å±¤ã®æ§æã¯åç´ãªNIOãµã¼ãã§ãããã詳細ãªèª¬æã¯çç¥ããã
sendfileã®å®è£
ã¯MessageSet#writeToã¡ã½ãããç¨ãã¦è¡ãããã
FileChannel#transferToã¡ã½ããã«ããã¦File-backedã¡ãã»ã¼ã¸ç¾¤ãç¨ãããã¨ã§
ããã»ã¹å
ã§ãããã¡ãªã³ã°ããããå¹ççãªãããã¡ãªã³ã°ãå®ç¾ãã¦ããã
ã¹ã¬ããã¢ãã«ã¨ãã¦ã¯1ã¤ã®acceptorã¹ã¬ããã¨ã¹ã¬ãããã¨ã«ç¹å®ã®æ°ã®ã³ãã¯ã·ã§ã³ãå¦çãã
ï¼®åã®ããã»ããµã¹ã¬ããã§æ§æãããã
ãã®ã¢ãã«ã¯Voldemortで用いているNIO SocketServerã«ããã¦å®è£
ãç°¡åãã¤é«éã§ãããã¨ã示ããã¦ããã
ãããã³ã«èªä½ã¯å°æ¥çã«ä»ã®è¨èªããã§ãç¨ãããããã·ã³ãã«ã«ä¿ã£ã¦ããã
17.ã¡ãã»ã¼ã¸
ã¡ãã»ã¼ã¸ã¯ãåºå®ãµã¤ãºã®ãããã¨å¯å¤é·ã®ä¸ç¢ºå®ãã¤ãé
åãã¤ãã¼ãã§æ§æããã¦ããã
ãããã«ã¯ããã©ã¼ããããã¼ã¸ã§ã³ã¨ç ´æãåãæ¨ã¦ãæ¤åºããCRC32ãã§ãã¯ãµã ãå«ãã§ããã
ä¸ç¢ºå®ã®è¦ç´ ã¯ç¾ç¶ã·ãªã¢ã©ã¤ãºã©ã¤ãã©ãªã®é²æ©ãæ¿ãããï¼ã¤ã«çµããã¨ã¯å¾çã§ã¯ãªããããããã¦æ®ãã¦ããã
ãã ãå½ç¶ãªããKafkaã使ç¨ãã¦ç¹å®ã®ã¢ããªã±ã¼ã·ã§ã³ãä½æããéã«ã¯ã·ãªã¢ã©ã¤ãºæ¹å¼ãé¸æããå¿
è¦ãåºã¦ããã
MessageSetã¤ã³ã¿ãã§ã¼ã¹ã¯ã¡ãã»ã¼ã¸ã®ã¤ãã¬ã¼ã¿ã»ãããéããNIOãã£ãã«ã¸ã®ãã«ã¯æ¸è¾¼ï¼ãã«ã¯èªè¾¼ã«ç¹åããæ§æã«ãªã£ã¦ããã
18.ã¡ãã»ã¼ã¸ãã©ã¼ããã
NByteã®ã¡ãã»ã¼ã¸ã¯ä¸è¨ã®ãã©ã¼ãããã¨ãªã£ã¦ããã
- 1.1Byte MagicByteï¼ãã©ã¼ãããå¤æ´ãå¯è½ã¨ããããã®èå¥ãã¤ãï¼
MagicByte == 0
- 2.4Byte CRC32ãã§ãã¯ãµã
- 3.N-5Byte ã¡ãã»ã¼ã¸ãã¤ãã¼ã
MagicByte == 1
- 2.1Byte attributesèå¥åï¼å§ç¸®ç¶æ ãã³ã¼ããã¯ç¶æ ãªã©ã示ãï¼
- 3.4Byte CRC32ãã§ãã¯ãµã
- 4.N-5Byte ã¡ãã»ã¼ã¸ãã¤ãã¼ã
19.ãã°
"my_topic"ã¨ãããããã¯å称ãæã¤2ãã¼ãã£ã·ã§ã³ãæã¤ãããã¯ã¯"my_topic_0"ã¨"my_topic_1"ã¨ãã
ï¼ã¤ã®ãã£ã¬ã¯ããªã¨ãã¡ãã»ã¼ã¸ãä¿æãããã¡ã¤ã«ç¾¤ããæ§æãããã
ãã°ãã¡ã¤ã«ã®ãã©ã¼ãããã¯"ãã°ã¨ã³ããª"ã®é
åã¨ãªã£ã¦ããã
ãã°ã¨ã³ããªã¯ãã¡ãã»ã¼ã¸é·ï¼NByteï¼ã4Byteã®æ´æ°ã§ä¿æãã¦ããã
åã¡ãã»ã¼ã¸ã¯å¯¾è±¡ãããã¯ï¼ãã¼ãã£ã·ã§ã³ä¸ã®å
¨ã¡ãã»ã¼ã¸ä¸ã®éå§ä½ç½®ã§ãããªãã»ããã64ãããæ´æ°ã§ä¿æãã¦ããã
ãã®ãªãã»ããã«ãã£ã¦ä¸æã«èå¥ãããã
ãã£ã¹ã¯ä¸ã«ä¿åããã¦ããéã®ã¡ãã»ã¼ã¸ãã©ã¼ãããã¯ä»¥ä¸ã®éãã
åãã°ãã¡ã¤ã«ã¯ãã¡ã¤ã«ä¸ã«ä¿æããæåã®ã¡ãã»ã¼ã¸ã®ãªãã»ããå¤ãå称ã«ä¿æããã
ãã®ãããæåã«ä½æããããã°ãã¡ã¤ã«å称ã¯ã00000000000.kafkaãã¨ãªãã
以å¾ã®åãã¡ã¤ã«ã®å称ã¯å¤§ä½Sæ¯ã®ééãæã¤ãã°ãã¡ã¤ã«ã¨ãªãã
ï¼ããã§ã®Sã¯è¨å®ãã¡ã¤ã«ã§è¨å®ãããæ大ãã°ãã¡ã¤ã«ãµã¤ãºã®å¤ï¼
ãã®ãã¤ããªãã©ã¼ããããæ¨æºã¤ã³ã¿ãã§ã¼ã¹ã¨ãã¦å³å¯ã«ç¶æãããã¨ã§ã
ProducerãBrokerãConsumeréã§éä¿¡ããéã«åã³ãã¼ãå¤æãæå°éã«æãã¦ããã
ãã£ã¹ã¯ä¸ã®ãã©ã¼ãããã¯ä¸è¨ã
message length : 4 bytes (value: 1+4+n) "magic" value : 1 byte crc : 4 bytes payload : n bytes
é常ãã¡ãã»ã¼ã¸ã®IDã¨ãã¦ãªãã»ããã¯ä½¿ç¨ãããªãã
ç§ãã¡ã®å
ã
ã®ã¢ã¤ãã£ã¢ã¯Producerã«ãã£ã¦çæãããGUIDãç¨ãã
åBrokerã§GUIDâãªãã»ããã®ãããã³ã°ãä¿æããã¨ãããã®ã ã£ãã
ããããä¸è¨ã®æ¹å¼ãæ¡ç¨ããå ´åConsumerã¯åãµã¼ãï¼Brokerï¼ï¼ã®IDãç¶æããªããã°ãªããªãé¢ä¿ä¸ã
GUIDã®ä¸ææ§ã確ä¿ãã¦ãæå³ããªããªãã
ããã«ãGUIDâãªãã»ããã®ãããã³ã°ãç¶æããããã®è¤éãã¯
ãã£ã¹ã¯ã«å¸¸æåæãããå¿
è¦ãããããã¤ã©ã³ãã ã¢ã¯ã»ã¹ãå¿
è¦ã¨ãªãéãã¤ã³ããã¯ã¹æ§é ãå¿
è¦ã¨ããã
ããã§ç§ãã¡ã¯ãã®ã«ãã¯ã¢ããæ§é ãåç´åããããã«
ãã¼ãã£ã·ã§ã³ï¼ãã¼ãIDã¨ãã¢ã§ç¨ãããã¨ã§ã¡ãã»ã¼ã¸ãä¸æã«èå¥å¯è½ãªã¢ãããã¯ãªã«ã¦ã³ã¿ãç¨ãããã¨ã«ããã
ãã®æ¹éå¤æ´ã«ãã£ã¦Consumerããè¤æ°ã®ã·ã¼ã¯ã並åã§èµ°ãç¶æ³ã§ãã£ã¦ãã«ãã¯ã¢ããæ§é ã¯åç´åãããã
å調å¢å ãããã¼ãã£ã·ã§ã³æ¯ã«ã¦ãã¼ã¯ã«å²ãæ¯ããããªãã»ãããç¨ãããã¨ã«ããã
ãªãã»ãããç¨ãã¦ã¡ãã»ã¼ã¸ã«ç´æ¥é£ã¶æ§é ãåç´åãããåºå®åãããå¦çã¨ãªã£ãã
å°ããªãã»ããã¯ConsumerAPIããé ããã¦ãããããå®è£
ã®è©³ç´°ã¯å¾ããå¤æ´ã§ãã
ç§ãã¡ã¯ããå¹ççãªã¢ããã¼ãã«ãããã対å¿ãç¶ãã¦ããã
æ¸è¾¼
ãã°ã«ãã¼ã¿ã追å ããéã常ã«æå¾ã®ãã¡ã¤ã«ã«ç´æ¥è¿½å ãããã¨ãå¯è½ã
ãã°ãã¡ã¤ã«ãµã¤ãºã1GBã®ãããªè¨å®å¯è½ãªæ大ãµã¤ãºã«éããå ´åã次ã®ãã¡ã¤ã«ãçæãããã
ãã°ã¯ï¼ã¤ã®ãã©ã¡ã¼ã¿ãåãã
ï¼ï¼ï¼¯ï¼³ã«å¯¾ãã¦å¼·å¶çã«ãã©ãã·ã¥ããã¾ã§ã®ã¡ãã»ã¼ã¸æ°
ï¼³ï¼ï¼¯ï¼³ã«å¯¾ãã¦å¼·å¶çã«ãã©ãã·ã¥ããã¾ã§ã®æé
ä¸è¨ã®è¨å®ã«ãã£ã¦ãã·ã¹ãã ã®ã¯ã©ãã·ã¥ãçºçããéã«å¤±ãããæ大ã®ã¡ãã»ã¼ã¸æ°ï¼ã¡ãã»ã¼ã¸ã®é ä¿¡æéãè¨å®ãããã¨ãå¯è½ã
èªè¾¼
èªã¿è¾¼ã¿ã¯ãªãã»ããã¨æ大èªã¿è¾¼ã¿ãã£ã³ã¯ãµã¤ãºï¼³ã渡ããã¨ã§è¡ããã¦ããã
èªã¿è¾¼ã¿ã®çµæãï¼³Byteã®ã¡ãã»ã¼ã¸ãå«ãã¡ãã»ã¼ã¸ã®ã¤ãã¬ã¼ã¿ãè¿ãããã
ï¼³ã®å¤ã¯ã©ã®ã¡ãã»ã¼ã¸ããã大ãããªããã¨ãæ³å®ãã¦ããããã¤ãã³ããé常ã§ãªã大ããªãµã¤ãºã¨ãªã£ã¦ããå ´åã
èªè¾¼ã¯ã¡ãã»ã¼ã¸ã®èªã¿è¾¼ã¿ãæåããã¾ã§è¤æ°åå®æ½ãããå®è¡ãããåæ°ã ãï¼³Byteã®ã¡ãã»ã¼ã¸é åãåè¨ãã¦ç¢ºä¿ãããã
æ大ã¡ãã»ã¼ã¸æ°ï¼æ大ã¡ãã»ã¼ã¸ãµã¤ãºã¯ãµã¼ããä¸å®ãµã¤ãºãè¶
ããã¡ãã»ã¼ã¸ãåä¿¡ããéã«æå¦ããå½¢ã§å®ç¾ãããã
ããã¯Consumerãåä¿¡å¯è½ãªæ大ãµã¤ãºããªã¼ãã¼ããªãããã«è¨å®ããã¦ããã
ããåä¿¡å´ãï¼ã¡ãã»ã¼ã¸ã®éä¸ã§åä¿¡ãçµäºãã¦ãã¾ã£ãå ´åããã°ã¨ã³ããªã®ããªã¡ã¼ã¿ãçºçããªãããããã«æ¤ç¥ã§ããã
ãªãã»ãããç¨ããå®éã®èªã¿è¾¼ã¿ããã»ã¹ã¯ã¾ãã¯ããã«ã©ã®ãã¡ã¤ã«ã«è©²å½ã®ã¡ãã»ã¼ã¸ãå«ã¾ããããç¹å®ããã
ãã®ä¸ã§ãã¡ã¤ã«åã«è¨è¿°ããããªãã»ããã¨èªè¾¼å¯¾è±¡ãªãã»ããã®å·®åãåã£ã¦èªè¾¼å ´æãç¹å®ããã
ãã®æ¤ç´¢å¦çã¯ãã¡ã¤ã«ãã¨ã«ç®¡çãããã¡ã¢ãªã«å¯¾ãã¦åç´ãªãã¤ããªãµã¼ãã®ããªã¨ã¼ã·ã§ã³ã¢ã«ã´ãªãºã ã«ããæ¤ç´¢ãå®æ½ãããã¨ã§å®ç¾ãã¦ããã
ãã®ãã°ã®æ¹å¼ã«ãã£ã¦Kafkaã¯ãä»æ¸ãè¾¼ã¾ããããã¡ã¤ã«ãå«ãã¦Consumerã®åå¾å¯¾è±¡ã«ãããã¨ãã§ããã
ãã®æ¹å¼ã¯SLAã¨ãã¦è¨å®ãããã©ã¡ã¼ã¿å
ã§Cosumerå´ããã°ã®å¦çã«å¤±æããå ´åã«ãæç¨ã
å°ããã®æ¹å¼ã¯åå¨ããªããªãã»ãããæå®ããå ´åã«ã¯OutOfRangeException ãçºçããããããã®ä¾å¤ãæã£ã¦ãã³ããªã³ã°ãè¡ããã¨ã
Consumerã«éä¿¡ãããã¡ãã»ã¼ã¸ã®ãã©ã¼ãããã¯ä¸è¨ã
MessageSetSend (fetch result) total length : 4 bytes error code : 2 bytes message 1 : x bytes ... message n : x bytes MultiMessageSetSend (multiFetch result) total length : 4 bytes error code : 2 bytes messageSetSend 1 ... messageSetSend n
åé¤
ãã°ãåé¤ããéãåæã«1ã¤ã®ãã°ã»ã°ã¡ã³ããåé¤ããã
ãã°ããã¼ã¸ã£ã«ã¯åãã¡ã¤ã«ãåé¤å¯¾è±¡ãã©ãããå¤æããããã®ããªã·ã¼ããã©ã°ã¤ã³æ¹å¼ã§è¿½å ãããã¨ãå¯è½ã
ç¾ç¶ã§ã¯ãæçµæ´æ°æå»ãNæ¥ä»¥ä¸åããããä¿æãããã°ã®éãæ°ããæ¹ããNGBä¿æãããã以å¤ãåé¤ãã¨ããæ¹å¼ãæç¨ã ã¨å¤æãã¦ããã
åé¤å¯¾è±¡ã¨ãªã£ããã¡ã¤ã«ã«å¯¾ãã¦æ¸è¾¼ã¿ï¼èªã¿è¾¼ã¿ã競åãããããªãã¿ã¼ã³ãåé¿ãããããã»ã°ã¡ã³ããªã¹ãã®å®è£
ã«ã³ãã¼ãªã³ã©ã¤ãæ¹å¼ãåã£ã¦ããã
ãã°ããã¼ã¸ã£ã§ã¯åé¤å¦çãèµ°ã£ã¦ããéã¯ã¤ãã¥ã¼ã¿ãã«ãªã»ã°ã¡ã³ããªã¹ãã®ã¹ãããã·ã§ãããä½æãã
ãã¤ããªãµã¼ãã¢ã«ã´ãªãºã ã¯ãã¡ããåç
§ããããã«ãã¦ããã
ä¿è¨¼
ãã°åºåæããã¡ã¤ã«ã«å¼·å¶çã«ãã©ãã·ã¥ããããä¿æã¡ãã»ã¼ã¸æ°ï¼ãè¨å®é
ç®ã¨ãã¦è¨å®å¯è½ã
Kafkaã®ããã»ã¹èµ·åæããã°ã®ãªã«ããªããã»ã¹ãèµ°ãã
ææ°ã®ãã°ã»ã°ã¡ã³ãä¸ã«ä¿æããã¦ããã¡ãã»ã¼ã¸ã¨ã³ããªãæå¹ã§ãããã¨ã確èªãã¦ããã
ã¡ãã»ã¼ã¸ã¨ã³ããªã¯ä¸è¨ã®æ¡ä»¶ãæºããå ´åæ£å¸¸ã¨å¤æããã
- ã¡ãã»ã¼ã¸ãµã¤ãºã¨ãªãã»ããå¤ã®åè¨å¤ããã¡ã¤ã«ãµã¤ãºããå°ãã
- ä¿åãã¦ããCRC32ãã§ãã¯ãµã å¤ãä¿æãã¦ããã¡ãã»ã¼ã¸ãã¤ãã¼ãã®ãã§ãã¯ãµã çµæã¨ä¸è´ãã¦ãã
ã¡ãã»ã¼ã¸ã®ç ´æ£ã¯ãã¡ã¤ã«ä¸ã§ä¸çªæå¾ã®æ£å¸¸ã¡ãã»ã¼ã¸ããã£ããªãã»ãã以éã
åé¤ãããã¨ã§è¡ãããã
å°ãï¼ç¨®é¡ã®åé¡ã«å¯¾å¦ããå¿ è¦ããããã¨ã«çæãããã¨ã
- ã·ã¹ãã ãã¯ã©ãã·ã¥ããããä¸æ£ãªã¡ãã»ã¼ã¸ãæ«å°¾ã«æ®ã£ã¦ãã
- ä¸æ£ãªã¡ãã»ã¼ã¸é¨ãè¨è¿°ããã¦ãã
ãã®ãããªåé¡ã«å¯¾å¦ããå¿
è¦ãããçç±ã¨ãã¦ãä¸è¬çã«ï¼¯ï¼³ã¯ãã¡ã¤ã«ã®inodeã¨å®ä½ãã¼ã¿ã®æ¸ãè¾¼ã¿é åæã¯ä¿è¨¼ãã¦ããªãããã
çµæãinodeãæ´æ°ãããå®ä½ãã¼ã¿ã®æ´æ°ã«å¤±æããå ´åããµã¤ãºã¯å¤§ãããå®éã«ã¯ä¸èº«ããªãã¨ãã£ãä¸æ´åãçºçããã
CRCãã§ãã¯ãµã ã¯ãããã£ãä¸æ´åãã¿ã¼ã³ã¸ã®å¯¾å¦ã®ããã«æè¼ãããã°ç ´å£ã®æ³¢åãé²ãã§ããã
20.åæ£æ¹å¼
以å¾ãBrokerã¨Consumerã®å調ã«ç¨ããZookeeperã®ãã£ã¬ã¯ããªæ§æã¨ã¢ã«ã´ãªãºã ã«ã¤ãã¦è¨è¿°ããã
Zookeeperä¸ã®ãã£ã¬ã¯ããªæ§æå¤ä¾
[xyz]ã¨ããå½¢ã§[]ã§å²ã£ãåæã¯ãããã¯åããã³ãã¼ã«ãã£ã¦å¤åããå¤ã示ãã
ãã®ã¾ã¾"xyz"ã¨ããZnodeãåå¨ãã¦ããã¨ã¯éããªãã
ä¾ã¨ãã¦ãã/topics/[topic]ãã¯/topicã¨ãããã£ã¬ã¯ããªã®é
ä¸ã«ãããã¯åã®ååãæã¤Znodeãåå¨ãããã¨ã示ãã
åæ§ã«ã[0...5]ãã¨è¨è¿°ããå ´åã¯0ã1ã2ã3ã4ã»ã»ã»ã¨ããå½¢ã§Znodeãåå¨ãããã¨ã示ãã
ã¾ããã->ãã¯å®éã®Znodeã®å¤ã示ããã¨ã«ä½¿ç¨ãããã
ä¾ãã°ãã/hello -> worldãã¨è¨è¿°ããå ´åãã/helloãã¨ããZnodeãåå¨ããå
容ã«ãworldããä¿æãããã¨ã示ãã
BrokerIDã¬ã¸ã¹ããª
/brokers/ids/[0...N] --> host:port (ephemeral node)
BrokerIDã¬ã¸ã¹ããªã«ã¯Consumerå´ããBrokerãè«ççã«ä¸æã«èå¥ã§ããIDãå称ã¨ãã¦æã¤Znodeãä¿æããã
ï¼è«ççã«ä¸æã«èå¥ã§ããIDï¼è«çIDã¯è¨å®é
ç®ã¨ãã¦æå®ããå¿
è¦ãããï¼
Brokerã¯èµ·åæã«ã/brokers/ids/ãé
ä¸ã«èªåã®è«çIDãæã¤Znodeãç»é²ããã
ãã®ããã«è«çIDãç¨ããç®çã¯ãBrokerãç©ççã«å¥ã®ãã¼ãã«ç§»åããããå¾ãªãç¶æ³ã«ãªã£ãå ´åã«
Consumerå´ã§ãã®ãã¨ããã³ããªã³ã°ããå¿
è¦ããªãããã«ãããããã
è«çIDç»é²æã«æ¢ã«ãã®IDã使ç¨ããã¦ããå ´åã¯ã¨ã©ã¼ã¨ãªãã
ãephemeral nodeãã®ããããããã®Znodeã¯Brokerããã»ã¹ãèµ·åãã¦ããéã®ã¿ç¶æãããçµäºããã¨æ¶ããã
ããã«ãã£ã¦Consumerå´ã¯Brokerãè½ã¡ããã¨ãæ¤ç¥å¯è½ã
Brokerãããã¯ãã£ã¬ã¯ããª
/brokers/topics/[topic]/[0...N] --> nPartions (ephemeral node)
åBrokerã¯[topic]ãã£ã¬ã¯ããªé ä¸ã«ãããã¯ã«å¯¾ãã¦èªåãä¿æãã¦ãããã¼ãã£ã·ã§ã³æ°ãç»é²ããã
Consumerï¼Consumerã°ã«ã¼ã
Consumerå´ãZookeeperä¸ã«èªåã®ç¶æ
ã«ã¤ãã¦ç»é²ãè¡ãã
ç»é²ãè¡ãçç±ã¯ãæ¶è²»éã®è¨ç®ã¨ãããã¯ï¼ãã¼ãã£ã·ã§ã³ãã¨ã«
ã©ãã¾ã§ã¡ãã»ã¼ã¸ãæ¶è²»ãããã示ããªãã»ãããå
±æããããã
è¤æ°ã®Consumerã¯Consumerã°ã«ã¼ããæ§æããã°ã«ã¼ãã§ãããããã¯ã«å¯¾ãããã¼ã¿ãå
±åã§ä½¿ç¨ãããã¨ãã§ããã
ããConsumerã°ã«ã¼ãã«æå±ããConsumerã«å¯¾ãã¦IDã§ãããgroup_idããå
±æããã
ä¾ãã°ã"foobar"ã¨ããå称ã®Consumerããã»ã¹ã3ã¤ã®ãã¼ãã«ã¾ããã£ã¦å®è¡ãããå ´åã
"foobar"ã¨ããIDããããã®Consumerããã»ã¹ç¾¤ã«å¯¾ãã¦ä¸ããã
ãã®ã°ã«ã¼ãIDã¯Consumerããã»ã¹ã®è¨å®å¤ã¨ãã¦æå®ããã
ãã®è¨å®ã«ãã£ã¦Consumerããã»ã¹ã¯èªåã®æå±ããã°ã«ã¼ããèªèããã
Consumerã°ã«ã¼ãã«æå±ããConsumerããã»ã¹éã¯ãããããã¯ã«å¯¾ãããã¼ãã£ã·ã§ã³ã
åºæ¥ãã ãåçã«ãªãããã«åãåãã
ï¼ãã¼ãã£ã·ã§ã³ã¯ï¼Consumerããã»ã¹ã«ãã£ã¦æ¶è²»ãããã
ConsumerIDã¬ã¸ã¹ããª
ãgroup_idãã®ä»ã«Consumerã«ã¯Consumerã®èå¥ã®ããã«ãconsumer_idãï¼UUIDå½¢å¼ã®ãã¹ãåï¼ãä¸æçã«å²ãå½ã¦ãããã
ãconsumer_idãã¯ä¸è¨ã®ãã£ã¬ã¯ããªé
ä¸ã«ä¿åãããã
/consumers/[group_id]/ids/[consumer_id] --> {"topic1": #streams, ..., "topicN": #streams} (ephemeral node)
åä¸ã°ã«ã¼ãå
ã®Consumerã¯åä¸ã®ãgroup_idããã£ã¬ã¯ããªé
ä¸ã«ãconsumer_idãã®Znodeãä½æãããã¨ã§ç»é²ããã
Znodeã¯
ãã®IDã¯åç´ã«ã°ã«ã¼ãå
ã§ã©ãã ãã®Consumerãçãã¦ãããã©ããã®å¤å¥ã«ç¨ããããã
BrokerIDã¨åæ§ã«ãephemeral nodeãã®ãããConsumerãè½ã¡ãããã®Znodeãæ¶ããã
Consumerã®ãªãã»ãããã¬ã¼ã¹
Consumerããã»ã¹ã¯ãªãã»ããã®æ大å¤ãåãã¼ãã£ã·ã§ã³ãã¨ã«ã©ãã¾ã§ã¡ãã»ã¼ã¸ãæ¶è²»ããããå¤å¥ããããã«è¨é²ããã
/consumers/[group_id]/offsets/[topic]/[broker_id-partition_id] --> offset_counter_value ((persistent node)
ãã¼ãã£ã·ã§ã³ãªã¼ãã¼ã®ã¬ã¸ã¹ããª
Brokerã®ãã¼ãã£ã·ã§ã³ã¯Consumerã°ã«ã¼ãæ¯ã«ããï¼Consumerã«ãã£ã¦æ¶è²»ãããã
Consumerã¯ã¡ãã»ã¼ã¸ã®æ¶è²»ãéå§ããåã«è©²å½ã®ãã¼ãã£ã·ã§ã³ã«å¯¾ãã¦ãªã¼ãã¼ã§ãããã¨ã確å®ãããå¿
è¦ãããã
ãªã¼ãã¼ã§ãããã¨ã確å®ãããããã«Consumerã¯ä¸è¨ã®ãã£ã¬ã¯ããªã«ãephemeral nodeããä½æããã
/consumers/[group_id]/owners/[topic]/[broker_id-partition_id] --> consumer_node_id (ephemeral node)
Brokerèµ·åæå¦ç
Brokerã¯åºæ¬ç¬ç«ãã¦ãããããBrokerãä¿æãã¦ããæ
å ±ã«ã¤ãã¦ã®ã¿ç»é²ãè¡ãã
Brokerãèµ·åããã¨Brokerã®ã¬ã¸ã¹ããªãã£ã¬ã¯ããªé
ä¸ã«Znodeãä½æãããã¹ãã¨ãã¼ãã®æ
å ±ãç»é²ããã
Brokerã¯ãããã¦èªããä¿æãã¦ãããããã¯ã¨ãã¼ãã£ã·ã§ã³ä¸è¦§ãBrokerãããã¯ã¬ã¸ã¹ããªé
ä¸ã«ç»é²ããã
æ°ãããããã¯ãä½æãããå ´åã¯ãã®é½åº¦ã¬ã¸ã¹ããªé
ä¸ã«ãããã¯Znodeã追å ãããã
Consumerèµ·åæå¦ç
Consumerèµ·åæãä¸è¨ã®å¦çãè¡ããã
- ãconsumer_idããæå±ã°ã«ã¼ãã®ãã£ã¬ã¯ããªé ä¸ã«ç»é²ãã
- ConsumerIDã¬ã¸ã¹ããªé ä¸ã«å¯¾ãã¦ZookeeperWatcherãè¨å®ããæ°ããConsumerã®è¿½å ãåé¤ãæ¤ç¥ã§ããããã«ãããï¼Consumerã°ã«ã¼ãé ä¸ã®Consumerã®ç¶æ ãå¤æ´ãããå ´åãã°ã«ã¼ãå ã®å ¨Consumerå ã§ãªãã©ã³ã¹ãèµ·åãããï¼
- BrokerIDã¬ã¸ã¹ããªé ä¸ã«å¯¾ãã¦ZookeeperWatcherãè¨å®ããæ°ããBrokerã®è¿½å ãåé¤ãæ¤ç¥ã§ããããã«ãããï¼BrokerIDã¬ã¸ã¹ããªé ä¸ã®Brokerã®ç¶æ ãå¤æ´ãããå ´åãã°ã«ã¼ãå ã®å ¨Consumerå ã§ãªãã©ã³ã¹ãèµ·åãããï¼
- ãããã¯ãã£ã«ã¿ã使ç¨ãã¦ããå ´åãBrokerãããã¯ãã£ã¬ã¯ããªé ä¸ã«å¯¾ãã¦ZookeeperWatcherãè¨å®ããæ°ãããããã¯ã®è¿½å ãæ¤ç¥ã§ããããã«ãããï¼ãããã¯ã追å ãããå ´åãããããããã¯ãã£ã«ã¿ã«åè´ãããã®ç¢ºèªãè¡ãããåè´ããå ´åã¯ã°ã«ã¼ãå ã®å ¨Consumerå ã§ãªãã©ã³ã¹ãèµ·åãããï¼
- èµ·åConsumerãæå±ããConsumerã°ã«ã¼ãã«å¯¾ãã¦ãªãã©ã³ã¹ãå¼·å¶å®è¡ãã
Consumerãªãã©ã³ã¹ã¢ã«ã´ãªãºã
Consumerãªãã©ã³ã¹ã¯ããConsumerã°ã«ã¼ãå
ã§ã©ã®Consumerãã©ã®ãã¼ãã£ã·ã§ã³ãæ¶è²»ããããåæããããã«è¡ãããã
Consumerãªãã©ã³ã¹ã¯ã°ã«ã¼ãå
ã®Consumerã®è¿½å åé¤ãBrokerã®è¿½å åé¤ãããªã¬ã¨ãã¦è¡ãããã
ï¼ãããã¯ãï¼Consumerã°ã«ã¼ããè¦ãå ´åãBrokerãã¼ãã£ã·ã§ã³ã¯ã°ã«ã¼ãå
ã®Consumeræ¯ã«åçã«å²ãæ¯ãããã
ï¼ãã¼ãã£ã·ã§ã³ã¯å¸¸ã«ï¼ã¤ã®Consumerã«ãã£ã¦æ¶è²»ãããã¨ããå®è£
ã«ãã£ã¦ãããã®ãªãã©ã³ã¹ã¯ã·ã³ãã«ã«ãªã£ã¦ããã
ããããçç±ã¨ãã¦ãï¼ãã¼ãã£ã·ã§ã³ã«å¯¾ãã¦è¤æ°ã®Consumerãç´ã¥ããããå ´åãããã¯ã¢ã«ã´ãªãºã ãå¿
è¦ã¨ãªãã競åãçºçããããã§ããã
å°ããã¼ãã£ã·ã§ã³ã®æ°ããConsumerã®æ°ã®æ¹ãå¤ãå ´åãããã¤ãã®Consumerã¯ãã¼ã¿ãä¸ååä¿¡ãããã¨ãã§ããªããããã®ç¹ã¯æ³¨æã
Consumerãªãã©ã³ã¹ã®éã以ä¸ã®ã¢ã«ã´ãªãºã ãç¨ãã¦ãªãã©ã³ã¹ãè¡ããã¨ã«ãããï¼Consumerãæ¥ç¶ãã«è¡ãBrokerã®æ°ãæãã¦ããã
Consumerãªãã©ã³ã¹ã®éè¡ãããå¦çã¯ä¸è¨ã
åæï¼
- PTã¯ãããããã¯ã«å¯¾ãããã¼ãã£ã·ã§ã³ã®å ¨ä½éåããã
- PTã«å«ã¾ãããã¼ãã£ã·ã§ã³ã¯Piï¼iã®å¤ã¯1ãTã¾ã§å¤åï¼ã¨è¨è¿°ãã
- CGã¯ããConsumerã°ã«ã¼ãã«å«ã¾ããConsumerå ¨ä½éåããã
- CGã«æå±ããConsumerã¯Ciï¼iã®å¤ã¯1ãGã¾ã§å¤åï¼ã¨è¨è¿°ãã
ãªãã©ã³ã¹å¦çï¼
- PTãã½ã¼ãããï¼çµæãåä¸Brokerä¸ã®ãã¼ãã£ã·ã§ã³ã¯åºã¾ãï¼
- CGãã½ã¼ããã
- ãã¼ãã£ã·ã§ã³æ°ï¼PTï¼ï¼Consumeræ°ï¼CGï¼ãå®è¡ãã¦å¤ï¼®ãç®åº
- ãã¼ãã£ã·ã§ã³ i * ï¼®ããã(i + 1) * ï¼® - 1 ãConsumer iã«å¯¾ãã¦å²ãæ¯ã
- Consumerãå ã ä¿æãã¦ãããã¼ãã£ã·ã§ã³ãªã¼ãã¬ã¸ã¹ããªãåé¤ãã
- Consumerããªãã©ã³ã¹å¾ã«èªã¿è¾¼ããã¼ãã£ã·ã§ã³ãªã¼ãã¬ã¸ã¹ããªãç»é²ãã
ãªãã©ã³ã¹ãããConsumerã§èµ·åãããå ´åãåä¸Consumerã°ã«ã¼ãå
ã®Consumerãåæã«ãªãã©ã³ã¹ãå®è¡ããå¿
è¦ããã
ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
æ¹ãã¦æ¯ãè¿ãã¨ãããªãã®éãèªãã§ãããã¨ããããã¾ãã
Consumerå´ããªãã»ããã管çããã¨ãããKafkaã®è¨è¨æ¹éã§ä¸çªç¹å¾´çãªåæã§ããã
ããã«ãã£ã¦åºæ¥ããã¨ãå¤ãããã§ãã¦ã
ãã®ãããã¯èªåãä½ãä½ãã¨ãã«ãåèã«ããã¦ããã ãã¾ãã