æ¨æ¸¬ããè¨æ¸¬ãã©ãããããããã§ãã
æ¨æ¥ãRecall.ai ã®ãªã³ã°ãããã¡ãã©ã®ããã«è¨è¨ãããã®ããèå¯ãã¾ããã
ãã®å¾ãHacker News ã®ã³ã¡ã³ããè¦ã¦ããã¨ãªã³ã°ãããã¡ã¯ãªã¼ãã¼ã¨ã³ã¸ãã¢ãªã³ã°ã§ãã£ã¨ç°¡åãªæ¹æ³ã¨ãã¦ä»¥ä¸ã®ææ³ãªã©ãææ¡ããã¦ãã¾ããã
- TCP ã®ã¦ã£ã³ãã¦ãµã¤ãºãå¤ãã
/dev/shm
ã使ã- å ±æã¡ã¢ãªã§ã®é信㯠Mojo ããµãã¼ããã¦ãã
WebSockets cost us $1M on our AWS bill | Hacker News
TCP ã®ã¦ã£ã³ãã¦ãµã¤ãºãå¤ããã¨ãã¦ããã¦ã¼ã¶ã¼ç©ºéã¨ã«ã¼ãã«ç©ºéã®ç¡é§ãªã¡ã¢ãªã³ãã¼ã®éã¯å¤ãããªãã®ã§ä»åã®ã¡ã¢ãªã³ãã¼ã®ããã«ããã¯ã«ã¯å¹ããªãæããã¾ãã
/dev/shm
ã«ã¤ãã¦ã¯ãMemory backed file ã«ãã¼ã¿ãæ¸ãè¾¼ãã§ãã®ãã¡ã¤ã«ã®ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã Unix ãã¡ã¤ã³ã½ã±ããã§éããã³ã³ã·ã¥ã¼ãå´ã§ mmap ããã°ã¡ã¢ãªã³ãã¼ã®åæ°ã¯å
±æã¡ã¢ãªã®ãªã³ã°ãããã¡ã®ææ³ã¨åããªã®ã§ãä¸èã®ä¾¡å¤ã¯ããã¾ãã
ãããããã¬ã¼ã ãã¨ã« tmpfs ã«ãã¡ã¤ã«ãä½æã㦠Unix ãã¡ã¤ã³ã½ã±ããçµç±ã§éä¿¡ã㦠mmap ããªãããªã¼ãã¼ããããããä¸ã«ãæ¸ãè¾¼ã¿æã«ã¯ã¡ã¢ãªãã¼ã¸ã®å²ãå½ã¦ãçºçããèªã¿è¾¼ã¿æã«ã¯ mmap ãããé åã®ãã¼ã¸ãã¼ãã«ãåããã¾ã§ãã¼ã¸ãã©ã«ãã大éã«çºçãããªã©ããªã¼ãã¼ãããã大ãããã§æ¬å½ã«ããã©ã¼ãã³ã¹ãè¯ãã®ãã©ããã¯æªããã§ãã
/dev/shm
ãç´æ¥ä½¿ãå ´åã¯ãããã¥ã¼ãµãæ»ãã æã«å¤§ããã®ã¡ã¢ãªããªã¼ã¯ããã®ã§ååããããã®æ»æ´»ç£è¦ãå¿
è¦ã«ãªãã¾ãããmemfd_create(2)
ã使ãã°èªåçã«ååããã¾ãã
Mojo ã«ã¤ãã¦ã¯ãRust ã®ãã¤ã³ãã£ã³ã°ã¯ã¾ã å®æãã¦ããªãã®ã§ä½¿ããªãã¨æãã¾ãããmojo::BigBuffer
ã¯å®è³ªçã«ã¯ä¸ã® /dev/shm
ã®ææ³ã¨åãã§ãã
ã¨ãããã¨ã§ããªã³ã°ãããã¡ã¨ Memory backed file ã Unix ãã¡ã¤ã³ã½ã±ããã§éã£ã¦ mmap ããææ³ã®ã©ã¡ããã©ã®ãããéãã®ããæ°ã«ãªã£ãã®ã§æ¤è¨¼ãã¦ã¿ã¾ããã
å®éã®æ¤è¨¼ã³ã¼ãã¯ææ«ã«åãè¾¼ãã§ããã¾ãããç¹å¾´ã¨ãã¦ã¯
- 3MB ã®åºå®é·ã®ã©ã³ãã ãªãã¼ã¿ãéä¿¡ãã
- ãããã¥ã¼ãµã¯ 3 ã¹ã¬ãããã並åã«ãããã 100 ãã¬ã¼ã ãã¤æ¸ãè¾¼ã¿ãã³ã³ã·ã¥ã¼ãã¯ã·ã³ã°ã«ã¹ã¬ããã§èªã¿è¾¼ã
- ãªã³ã°ãããã¡ã®æ大æ°ã¨ Unix ãã¡ã¤ã³ã½ã±ããã§åæã«éããã®ã¯æ大 30 ãã¬ã¼ã åã¾ã§
- åä¸ããã»ã¹å ã®å¥ã®ã¹ã¬ããããããããéãããããã©ã¼ãã³ã¹ç¹æ§ã¨ãã¦ã¯å¥ããã»ã¹ã®å ´åã¨å¤ãããªãã¯ã
- Unix ãã¡ã¤ã³ã½ã±ããã使ã£ãã¹ããããªã³ã°ã¯è¤æ°ã³ãã¯ã·ã§ã³ãå¿ è¦ã«ãªãã®ã§ã¨ããããã»ããã©ã§ä»£æ¿
- memfd 㯠Linux ã«ãããªãã¦ãmacOS ã§éçºã§ããªãã£ãã®ã§ãLinux 㨠macOS ã®ä¸¡æ¹ã§ä½¿ãã
tempfile
ã¯ã¬ã¼ãã§ä»£æ¿ãå®æ 㯠Memory backed file ãªã®ã§ããã©ã¼ãã³ã¹ç¹æ§ã¯åãã¯ã
çµæ
- Linux
- ãªã³ã°ãããã¡: 1.95 s ããã
- Memory backed file: 5.2 s ããã
- macOS
- ãªã³ã°ãããã¡: 750 ms ããã
- Memory backed file: 10 s ããã
ãªã³ã°ãããã¡ã®æ¹ãçµæ§éãã§ããmacOS ã§ã¯ Memory backed file ã®æ¹ãé ãããã®ã§ä½ãå¥ã®åé¡ããããããªæ°ããã¾ãã
Linux (AWS EC2)
ãªã³ã°ãããã¡
$ for i in {1..5}; do ./cmp_ringbuffer/target/release/cmp_ringbuffer; done producer 2 producer 1 producer 0 start producer 0 finished producer 1 finished producer 2 finished finished: 1.973099031s producer 2 producer 1 producer 0 start producer 2 finished producer 1 finished producer 0 finished finished: 1.964035006s producer 2 producer 1 producer 0 start producer 2 finished producer 0 finished producer 1 finished finished: 1.956276696s producer 2 producer 1 producer 0 start producer 2 finished producer 0 finished producer 1 finished finished: 1.968726078s producer 2 producer 1 producer 0 start producer 2 finished producer 1 finished producer 0 finished finished: 1.959291665s
Memory backed file
$ for i in {1..5}; do ./cmp_memfd/target/release/cmp_memfd; done producer 2 producer 1 producer 0 start producer 1 finished producer 2 finished producer 0 finished finished: 5.206459836s producer 2 producer 1 producer 0 start producer 1 finished producer 2 finished producer 0 finished finished: 5.225634239s producer 2 producer 1 producer 0 start producer 1 finished producer 2 finished producer 0 finished finished: 5.207194755s producer 2 producer 1 producer 0 start producer 0 finished producer 1 finished producer 2 finished finished: 5.216124744s producer 2 producer 1 producer 0 start producer 2 finished producer 1 finished producer 0 finished finished: 5.194187799s
macOS (æå ã® Macbook Pro 2018)
ãªã³ã°ãããã¡
$ for i in {1..5}; do ./cmp_ringbuffer/target/release/cmp_ringbuffer; done producer 0 producer 1 producer 2 start producer 2 finished producer 1 finished producer 0 finished finished: 717.866646ms producer 0 producer 2 producer 1 start producer 0 finished producer 2 finished producer 1 finished finished: 733.328122ms producer 1 producer 0 producer 2 start producer 0 finished producer 1 finished producer 2 finished finished: 736.151382ms producer 1 producer 2 producer 0 start producer 0 finished producer 2 finished producer 1 finished finished: 740.951105ms producer 0 producer 2 producer 1 start producer 2 finished producer 1 finished producer 0 finished finished: 751.015461ms
Memory backed file
$ for i in {1..5}; do ./cmp_memfd/target/release/cmp_memfd; done producer 0 producer 1 producer 2 start producer 1 finished producer 0 finished producer 2 finished finished: 10.866407023s producer 0 producer 2 producer 1 start producer 0 finished producer 1 finished producer 2 finished finished: 11.167087375s producer 2 producer 1 producer 0 start producer 1 finished producer 2 finished producer 0 finished finished: 10.824447892s producer 0 producer 2 producer 1 start producer 1 finished producer 0 finished producer 2 finished finished: 10.833614174s producer 0 producer 2 producer 1 start producer 1 finished producer 0 finished producer 2 finished finished: 11.07388444s