๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Node.js

[Node.js] ๋…ธ๋“œ๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

728x90

๐Ÿ˜ฒ Node.js๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

๊ณต์‹๋ฌธ์„œ์— ๋”ฐ๋ฅด๋ฉด, Node.js๋Š” Chrome V8 Javascript ์—”์ง„์œผ๋กœ ๋นŒ๋“œ๋œ Javascript ๋Ÿฐํƒ€์ž„์ด๋‹ค.

์ž ๊น, ๊ทธ๋Ÿผ Chrome V8 Javascript๋Š” ๋ฌด์—‡์ด๊ณ , ๋Ÿฐํƒ€์ž„์€ ๋ฌด์—‡์ผ๊นŒ?

๋จผ์ € Chrome V8์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž.

 

โœ”๏ธŽ Chrome V8 ์—”์ง„์ด๋ž€?

๊ณต์‹ ๋ฌธ์„œ์— ๋”ฐ๋ฅด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. C++๋กœ ์“ฐ์—ฌ์ง„ ์˜คํ”ˆ์†Œ์Šค๋กœ ๋†’์€ ํผํฌ๋จผ์Šค์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ *์›น ์–ด์…ˆ๋ธ”๋ฆฌ ์—”์ง„์ด๋‹ค. Chrome๊ณผ Node.js ๊ทธ๋ฆฌ๊ณ  ๋‹ค๋ฅธ ๊ฒƒ๋“ค์—๋„ ์“ฐ์ธ๋‹ค. ECMAScript์™€ ์›น ์–ด์…ˆ๋ธ”๋ฆฌ๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ , ์œˆ๋„์šฐ7 ์ด์ƒ๋ฒ„์ „, MacOs 10.12 ์ด์ƒ ๋ฒ„์ „... ๋“ฑ์—์„œ ๋Œ์•„๊ฐ„๋‹ค. V8์—”์ง„์€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰๋˜๊ฑฐ๋‚˜ C++ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋„ ์“ธ ์ˆ˜ ์žˆ๋‹ค.

 

* ์›น ์–ด์…ˆ๋ธ”๋ฆฌ : C++๋“ฑ์˜ ์–ธ์–ด๋กœ ์ž‘์„ฑ๋œ ํ”„๋กœ๊ทธ๋žจ์„ ์›น์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์คŒ. ์ตœ์‹  ์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ƒˆ๋กœ์šด ์œ ํ˜•์˜ ์ฝ”๋“œ.

V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors. V8 can run standalone, or can be embedded into any C++ application.

 

โœ”๏ธŽ Run time ์ด๋ž€?

 

์š”์•ฝ

: ๋Ÿฐํƒ€์ž„์—๋Š” ๋Ÿฐํƒ€์ž„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๋Ÿฐํƒ€์ž„ ์‹œ์Šคํ…œ์ด ์žˆ๋‹ค.

: ๋Ÿฐํƒ€์ž„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋˜๋Š” ๋„์ค‘์— ํ”„๋กœ๊ทธ๋žจ ์–ธ์–ด์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

: ๋Ÿฐํƒ€์ž„ ์‹œ์Šคํ…œ์€ ์ปดํ“จํ„ฐ ์–ธ์–ด๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ์†Œํ”„ํŠธ์›จ์–ด์ด๋‹ค. (์‹คํ–‰ํ•ด์ฃผ๋Š” ํ™˜๊ฒฝ, ์‹คํ–‰ํ•ด์ฃผ๋Š” ๊ฒƒ)

์˜ˆ๋ฅผ ๋“ค์–ด, ๋งŒ์•ฝ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๊ฐ€ ์žˆ๋‹ค๋ฉด

console.log("Hello K-World!");

๋Ÿฐํƒ€์ž„ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ํ•˜๊ธฐ ์ „์—๋Š” ๊ทธ๋ƒฅ ์ฝ”๋“œ์ด๋‹ค. ๋Ÿฐํƒ€์ž„ ํ™˜๊ฒฝ์—์„œ ์ด ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด "Hello K-World"๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

 

์ž์„ธํžˆ

- run time library

์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ, ๋Ÿฐํƒ€์ž„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋žจ์˜ ๋Ÿฐํƒ€์ž„(์‹คํ–‰) ์ค‘์— ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์— ๋‚ด์žฅ๋œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ปดํŒŒ์ผ๋Ÿฌ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํŠน์ˆ˜ ํ”„๋กœ๊ทธ๋žจ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค. ์—ฌ๊ธฐ์—๋Š” ์ž…๋ ฅ, ์ถœ๋ ฅ ๋˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ๊ธฐ๋Šฅ์ด ํฌํ•จ๋œ๋‹ค.

In computer programming, a runtime library is a special program library used by a compiler, to implement functions built into a programming language, during the runtime (execution) of a computer program. This often includes functions for input and output, or for memory management.

 

- run time system

๋Ÿฐํƒ€์ž„ ์‹œ์Šคํ…œ(๋Ÿฐํƒ€์ž„ ์‹œ์Šคํ…œ์ด๋ผ๊ณ  ๋ถ€๋ฅด๊ฑฐ๋‚˜ ๋Ÿฐํƒ€์ž„์ด๋ผ๊ณ  ๋ถ€๋ฆ„)์€ ๋ช‡๋ช‡ ์ปดํ“จํ„ฐ ์–ธ์–ด๋กœ ์ž‘์„ฑ๋œ ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋žจ์˜ ์‹คํ–‰์„ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์„ค๊ณ„๋œ ์†Œํ”„ํŠธ์›จ์–ด์ด๋‹ค. ๋Ÿฐํƒ€์ž„ ์‹œ์Šคํ…œ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋กœ์šฐ ๋ ˆ๋ฒจ(์ €์ˆ˜์ค€) ๋ช…๋ น์˜ ๊ตฌํ˜„์„ ํฌํ•จํ•˜๊ณ  ํ•˜์ด ๋ ˆ๋ฒจ(๊ณ ์ˆ˜์ค€)์˜ ๋ช…๋ น ๋˜ํ•œ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์œ ํ˜• ๊ฒ€์‚ฌ, ๋””๋ฒ„๊น…, ์ฝ”๋“œ ์ƒ์„ฑ, ์ตœ์ ํ™”๊นŒ์ง€ ์ง€์›ํ•œ๋‹ค. ๋ช‡๋ช‡์˜ ๋Ÿฐํƒ€์ž„ ์‹œ์Šคํ…œ ์„œ๋น„์Šค๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ์—‘์„ธ์Šค ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ž‘์—… ์Šค์ผ€์ฅด๋ง, ๋ฆฌ์†Œ์Šค ๊ด€๋ฆฌ ๊ฐ™์€ ๋‹ค๋ฅธ ์„œ๋น„์Šค๋“ค์€ ์—‘์„ธ์Šคํ•  ์ˆ˜ ์—†๋‹ค.

A run-time system (also called runtime system or just runtime) is software designed to support the execution of computer programs written in some computer language. The run-time system contains implementations of basic low-level commands and may also implement higher-level commands and may support type checking, debugging, and even code generation and optimization. Some services of the run-time system are accessible to the programmer through an application programming interface, but other services (such as task scheduling and resource management) may be inaccessible.

stackover flow (Wikipedia ๋Ÿฐํƒ€์ž„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ / ๋Ÿฐํƒ€์ž„ ์‹œ์Šคํ…œ)

 

 

๊ทธ๋ž˜์„œ ๋‹ค์‹œ Node.js๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€๋กœ ๋Œ์•„๊ฐ€์ž๋ฉด, ๋…ธ๋“œ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•ด์ฃผ๋Š” ๊ฒƒ(๋Ÿฐํƒ€์ž„ ์‹œ์Šคํ…œ)์ด๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ๊ฒ ๋‹ค.

 

๊ธฐ์กด์—๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ๊ทธ๋žจ์„ ์›น ๋ธŒ๋ผ์šฐ์ € ์œ„์—์„œ๋งŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. (๋ธŒ๋ผ์šฐ์ €๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋Ÿฐํƒ€์ž„์„ ๋‚ด์žฅํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.) ๊ทธ๋ž˜์„œ ๋ธŒ๋ผ์šฐ์ € ์™ธ์˜ ํ™˜๊ฒฝ์—์„œ๋„ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ์—ฌ๋Ÿฌ ์‹œ๋„๊ฐ€ ์žˆ์—ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹คํ–‰์†๋„ ๋ฌธ์ œ ๋•Œ๋ฌธ์— ํฐ ํ˜ธ์‘์„ ์–ป์ง€ ํฐ ํ˜ธ์‘์€ ์–ป์ง€ ๋ชปํ–ˆ๋‹ค๊ณ  ํ•œ๋‹ค.

 

๊ทธ๋Ÿฐ๋ฐ! 2008๋…„ ๊ตฌ๊ธ€์ด V8์—”์ง„์„ ์‚ฌ์šฉํ•œ ํฌ๋กฌ์„ ์ถœ์‹œํ•˜๋ฉด์„œ ์ƒํ™ฉ์ด ๋ฐ”๋€Œ์—ˆ๋‹ค. V8์—”์ง„์€ ๊ทธ๋™ํ•œ ์‹œ๋„ํ•˜๋˜ ์—ฌ๋Ÿฌ ๋‹ค๋ฅธ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์—”์ง„๊ณผ ๋‹ค๋ฅด๊ฒŒ ๋งค์šฐ ๋นจ๋ž๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์˜คํ”ˆ ์†Œ์Šค์˜€๋‹ค. ์ด๋Ÿฌํ•œ ์†๋„ ๋ฌธ์ œ, ๊ทธ๋ฆฌ๊ณ  ์˜คํ”ˆ์†Œ์Šค๋กœ ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜๋ฉด์„œ ๋ผ์ด์–ธ ๋‹ฌ(Ryan Dahl)์ด 2009๋…„ V8 ์—”์ง„ ๊ธฐ๋ฐ˜์˜ ๋…ธ๋“œ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ–ˆ๋‹ค.

 

๋…ธ๋“œ์˜ ๋‚ด๋ถ€๊ตฌ์กฐ from Node.js ๊ต๊ณผ์„œ

 

๋…ธ๋“œ๋Š” V8๊ณผ ํ•จ๊ป˜ libuv๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ์‚ฌ์šฉํ•œ๋‹ค. V8๊ณผ libuv๋Š” C์™€ C++๋กœ ๊ตฌํ˜„๋˜์–ด์žˆ๊ณ , ๋‚ด๊ฐ€ ์ฝ”๋”ฉํ•œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋…ธ๋“œ๊ฐ€ V8 liuv์— ์—ฐ๊ฒฐํ•ด์ค€๋‹ค๊ณ  ํ•œ๋‹ค.

 

libuv ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋…ธ๋“œ์˜ ํŠน์„ฑ์ธ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜, ๋…ผ ๋ธ”๋กœํ‚น I/O ๋ชจ๋ธ์„ ๊ตฌํ˜„ํ•˜๊ณ  ์žˆ๋‹ค.

 

๊ทธ๋ ‡๋‹ค๋ฉด ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜, ๋…ผ ๋ธ”๋กœํ‚น I/O๋Š” ๋˜ ๋ฌด์—‡์ผ๊นŒ?

๋‹ค์Œ ๊ธ€์—์„œ ์ด๋ฒคํŠธ์™€ ๋…ผ ๋ธ”๋กœํ‚น I/O์— ๋Œ€ํ•ด ๋” ์•Œ์•„๋ณด๋ ค๊ณ  ํ•œ๋‹ค.

 

 

 

 

 

 

์ฐธ๊ณ ์ž๋ฃŒ 

node.js ๊ณต์‹๋ฌธ์„œ https://nodejs.org/ko/    

node.js ๊ต๊ณผ์„œ https://thebook.io/080229/ch01/01/    

Chrome V8 ์—”์ง„ https://v8.dev/

WebAssembly ๋ชจ์งˆ๋ผ ๊ณต์‹๋ฌธ์„œ https://developer.mozilla.org/ko/docs/WebAssembly  

What is run time? https://stackoverflow.com/questions/3900549/what-is-runtime

 

728x90