Nodejs - gksrlfw/study GitHub Wiki
CLS (Continuation local storage)
μ€λ λλ₯Ό νμ©ν νλ‘κ·Έλλ°μμλ μ€νλλ μ€λ λμ 컨ν μ€νΈλ‘ ν μμ²μ λν κ³΅ν΅ μ€ν 리μ§(TLS)λ₯Ό νμ©ν μ μμ΅λλ€. μ±κΈμ€λ λμΈ μλ°μ€ν¬λ¦½νΈμ μ€ννκ²½μΈ Node.js μμλ TLS μ λΉμ·ν κΈ°λ₯μ νμ©νκΈ° μν΄ CLS λΌλ κ°λ μ λ§λ€μκ³ , μ΄λ₯Ό μ΄μ©νλ©΄ μμ²μ λν 컨ν μ€νΈλ₯Ό μ μ§ν μ μμ΅λλ€.
CLS λ Thread local storage μ²λΌ λμνμ§λ§ μ€λ λ λμ λ Έλ μ€νμΌμ μ½λ°± 체μΈμ κΈ°λ°μΌλ‘ νλ μ€ν 리μ§μ λλ€. μΌλ°μ μΈ μ¬μ©λ°©λ²μΌλ‘λ, cls namespace λ₯Ό μμ±νκ³ μμ²μ CLS Context λ₯Ό μμ±νλ©΄ μ€νλλ λΉλκΈ° 리μμ€μ λν΄ μΌλ ¨μ 체μΈμ νμ±ν©λλ€. μμΈν μ¬νμ μλμμ νμΈν μ μμ΅λλ€.
cls-hooked: https://github.com/Jeff-Lewis/cls-hooked logging with cls hooked: https://blog.goncharov.page/nodejs-logging-made-right
CLS λ typeORM, Sequelize μ κ°μ ORM μμμ transaction propagation, logging request ID μ μ§ λ±μ μ¬μ©λ μ μμ΅λλ€.
EventEmitter
cls-rtracer μ κ°μ λΌμ΄λΈλ¬λ¦¬λ₯Ό 보면 λ΄λΆμμ μ΄λ²€νΈλ₯Ό bind νλ κ²½μ°λ₯Ό νμΈν μ μμ΅λλ€. request / response μ μ μλμ΄μλ λͺλͺ μ΄λ²€νΈλ λ€λ₯Έ 컨ν μ€νΈμμ μ€νλ μ μλ€κ³ ν©λλ€.
cls-rtracer: https://github.com/puzpuzpuz/cls-rtracer Proposal: https://github.com/nodejs/node/issues/33723
async_hooks
async_hooks λ λΉλκΈ° 리μμ€λ₯Ό μΆμ ν μ μλ λ©μλλ₯Ό μ 곡ν©λλ€. Node.js μμ CLS λ₯Ό ꡬννλ κ²μ μ΄μ©λ©λλ€. μμ§ Experimental μΈ κΈ°λ₯μ΄μ§λ§, Google μ Tracer λ΄λΆμμ μ΄λ₯Ό μ΄μ©νμ¬ CLS λ₯Ό ꡬνν κ²μ 보면 μΌλ°μ μΈ κ²½μ°μλ μ¬μ©ν΄λ 무방ν λ― ν©λλ€.
nodejs async_hooks: https://nodejs.org/api/async_hooks.html
λΉλκΈ° 리μμ€
λΉλκΈ° 리μμ€λ λΉλκΈ° μμ μ μΌλΆλ‘ μμ±λλ©°, λΉλκΈ° μμ μ μΆμ νλκ²μ μ¬μ©λλ κ°μ²΄μ λλ€. λΉλκΈ° μμ μ΄ μλ£λλ©΄ μ½λ°±μ΄ μ€νλλ©° μλ²½ν μ’ λ£λλ©΄ κ°λΉμ§μ»¬λ ν λ©λλ€.
https://yceffort.kr/2021/08/async-resources-async-hooks
async_hooks μ±λ₯ μ΄μ
https://news.ycombinator.com/item?id=19310213
Todo
async_hooks proposal https://docs.google.com/document/d/1g8OrG5lMIUhRn1zbkutgY83MiTSMx-0NHDs8Bf-nXxM/edit#heading=h.6kknmf22ixwc https://docs.google.com/document/d/1y4lF-iQhhuSOgzlPIBbfCT4IUpg-in3az5Q87C7aY3Q/edit#