๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐ•์˜ ์ •๋ฆฌ/CLASS101 ๋ฐฑ์—”๋“œ ์‹œ์Šคํ…œ ์‹ค๋ฌด

Chapter2 - CPU Bound ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

by ์ฃผ๋ฐœ2 2021. 2. 22.
๋ฐ˜์‘ํ˜•

 ์•ˆ๋…•ํ•˜์„ธ์š”~ ์ด์ „์— ์šด์˜ํ•˜๋˜ ๋ธ”๋กœ๊ทธ ๋ฐ GitHub, ๊ณต๋ถ€ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜๋Š” Study-GitHub ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค!

 ๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ

 GitHub

Study-GitHub

 ๐Ÿ”


โœ” CLASS101 ๋ฐฑ์—”๋“œ ์‹œ์Šคํ…œ ์‹ค๋ฌด - Chapter2 CPU Bound ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

์•ˆ๋…•ํ•˜์„ธ์š”, ํด๋ž˜์Šค101 ๋ฐฑ์—”๋“œ ์‹œ์Šคํ…œ ์‹ค๋ฌด ๊ฐ•์˜๋ฅผ ๋“ฃ๊ณ , ๋ณต์Šต ์ฐจ์›์œผ๋กœ ์ •๋ฆฌํ•˜์—ฌ ๋‚จ๊ธฐ๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค!

ํ˜น์‹œ ๋ฌธ์ œ๊ฐ€ ๋œ๋‹ค๋ฉด ๊ธ€์„ ์‚ญ์ œํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค !!

 

class101.net/products/5fc4a3b4fc231b000d85661b

 

ํ˜„์ง ๋Œ€๊ธฐ์—… ๊ฐœ๋ฐœ์ž ํ‘ธ์™€ ํ•จ๊ป˜ํ•˜๋Š” ์ง„์งœ ๋ฐฑ์—”๋“œ ์‹œ์Šคํ…œ ์‹ค๋ฌด!

IT ๋Œ€๊ธฐ์—…๋“ค์˜ ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ๊ณต๊ณ ๋ฅผ ๋ณธ ์  ์žˆ๋‚˜์š”? ๐Ÿ“์œ„ ๋ฐ‘์ค„ ์นœ ๋ถ€๋ถ„์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ๋„๋ก ์ปค๋ฆฌํ˜๋Ÿผ์„ ๊ตฌ์„ฑํ–ˆ์–ด์š”. ๊ฒ‰๋ณด๊ธฐ์—” ์–ด๋ ค์›Œ ๋ณด์ด์ง€๋งŒ, ๊ฒฐ๊ตญ ๋ฐฐ์šฐ๊ณ  ๋‚˜๋ฉด ๋‚˜๋„ ์ €๋Ÿฐ ๊ณณ์—์„œ ์ผํ•  ์ˆ˜ ์žˆ

class101.net


 

 

โœ” CPU๋ฅผ ๊ทน๋‹จ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

ํ”„๋กœ๊ทธ๋žจ๊ณผ ํ”„๋กœ์„ธ์Šค์˜ ์ฐจ์ด ?

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ์ผ๋ฐ˜์ ์œผ๋กœ ํ•˜๋“œ๋””์Šคํฌ์— ์ €์žฅ๋˜์–ด ์žˆ๋Š”๋ฐ, ์ด๊ฒƒ์„ ํ”„๋กœ๊ทธ๋žจ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

ํ•˜๋“œ๋””์Šคํฌ์— ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰์‹œํ‚ค๋ฉด, ์ด ํ”„๋กœ๊ทธ๋žจ์˜ ๋‚ด์šฉ์€ ๋ฉ”๋ชจ๋ฆฌ ์œ„์— ์˜ฌ๋ผ๊ฐ€๊ณ  ์ด๊ฒƒ์„ ํ”„๋กœ์„ธ์Šค๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

• I/O ์—ฐ์‚ฐ์„ ์ ๊ฒŒํ•˜๊ณ , CPU ์—ฐ์‚ฐ์„ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ => CPU๋ฅผ ํŠน๋ณ„ํžˆ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

    Hash(MD5 Hash)๋ฅผ ํ†ตํ•ด CPU ์—ฐ์‚ฐ์„ ๋†’์ด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

 

 

์•„๋ž˜์˜ ์‚ฌ์ดํŠธ์—์„œ Spring Boot ํ”„๋กœ์ ํŠธ๋ฅผ Clone ํ•ฉ๋‹ˆ๋‹ค.

github.com/lleellee0/cpu-bound-application

 

 

* DataTypeConverter ํด๋ž˜์Šค๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์™€์„œ pom.xml์— ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

		<dependency>
			<groupId>javax.xml.bind</groupId>
			<artifactId>jaxb-api</artifactId>
			<version>2.3.1</version>
		</dependency>

 

 

 

์Šคํ”„๋ง ๋ถ€ํŠธ๋ฅผ ์‹คํ–‰ํ•˜๊ณ , localhost:80/hash/123 URL๋กœ ์ ‘๊ทผํ–ˆ์„ ๋•Œ, ๋ฌธ์ž์—ด์ด ์ถœ๋ ฅ๋˜๋ฉด ์ •์ƒ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.

 

โœ” Spring Boot ํ”„๋กœ์ ํŠธ๋ฅผ GCP์— ๋ฐฐํฌํ•˜๊ธฐ

Spring Boot ํ”„๋กœ์ ํŠธ๋ฅผ jar ํŒŒ์ผ๋กœ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

Maven > Lifecycle > deploy ๋”๋ธ” ํด๋ฆญ

 

 

 

Maven ๋นŒ๋“œ๋Š” ์‹คํŒจํ•˜์ง€๋งŒ, jar ํŒŒ์ผ์€ ์ƒ์„ฑ์ด ๋ฉ๋‹ˆ๋‹ค.

* jar ํŒŒ์ผ์„ GitHub์— ์˜ฌ๋ฆฌ๊ณ , GCP๊ฐ€ GitHub์˜ ํŒŒ์ผ์„ ๋ฐ›์•„๊ฐ€๋„๋ก ํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

 

 

 

GCP์—์„œ ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฆ„, ๋ฆฌ์ „(์„œ์šธ), ๋จธ์‹  ์œ ํ˜•(e2-micro), ๋ถ€ํŒ… ๋””์Šคํฌ(CentOS 7), ๋ฐฉํ™”๋ฒฝ(HTTP, HTTPSํ—ˆ์šฉ) ์œผ๋กœ ์ˆ˜์ •ํ•˜๊ณ  ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

 

์ธ์Šคํ„ด์Šค ์ƒ์„ฑ์ด ์™„์„ฑ๋˜๋ฉด SSH๋กœ ์—ฐ๊ฒฐํ•ด์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด wget๊ณผ Java๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.(์ค‘๊ฐ„์— y๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค)

$ sudo yum install wget

$ sudo yum install java

 

 

์„ค์น˜๊ฐ€ ๋๋‚˜๋ฉด wget์œผ๋กœ GitHub์— ์˜ฌ๋ฆฐ jar ํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›์Šต๋‹ˆ๋‹ค.

github.com/lleellee0/class101-files/blob/main/cpu-0.0.1-SNAPSHOT.jar

์œ„ ์‚ฌ์ดํŠธ์—์„œ Download ๋ฒ„ํŠผ ์šฐํด๋ฆญ > ๋งํฌ ์ฃผ์†Œ ๋ณต์‚ฌ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

 

 

๊ทธ ํ›„ SSH์—์„œ wget์„ ํ†ตํ•ด jar ํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›์Šต๋‹ˆ๋‹ค.

$ wget ๋งํฌ ์ฃผ์†Œ(URL)

 

 

 

 

๊ทธ ํ›„ Java๋กœ jar ํŒŒ์ผ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

$ sudo java -jar cpu-0.0.1-SNAPSHOT.jar

์œ„์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋‚˜ํƒ€๋‚˜๋ฉด ์Šคํ”„๋ง ๋ถ€ํŠธ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰์ด ๋œ๊ฑด๋ฐ์š”,

GCP์—์„œ ์ธ์Šคํ„ด์Šค์˜ ์™ธ๋ถ€ IP/hash/{input} ์œผ๋กœ ์ ‘๊ทผ์„ ํ•ด๋ด…๋‹ˆ๋‹ค.

 

 

 

์ •์ƒ์ ์œผ๋กœ ์ ‘๊ทผ์ด ๋ฉ๋‹ˆ๋‹ค. ๐Ÿ˜

 

 

 

๊ฐœ๋ฐœ์ž ๋„๊ตฌ(F12) > Network > ์ƒˆ๋กœ๊ณ ์นจ (HashController)

    Time: 193 ms

 

 

๊ฐœ๋ฐœ์ž ๋„๊ตฌ(F12) > Network > ์ƒˆ๋กœ๊ณ ์นจ (CpuApplication)

     Time: 51 ms

 

 

๋Œ€๋žต ์œ„์˜ ๊ฒฐ๊ณผ๋ฅผ ๋ดค์„๋•Œ, HashController์˜ ์‹œ๊ฐ„(193ms) - CpuApplication์˜ ์‹œ๊ฐ„(51ms) ์˜ ๊ฒฐ๊ณผ์ธ

140ms ์ •๋„๊ฐ€, MD5 Hash ๋ฅผ 100,000๋ฒˆ ์ •๋„ ์ˆ˜ํ–‰ํ•˜๋Š” ์‹œ๊ฐ„์ด๋ผ๊ณ  ์ƒ๊ฐ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


 

 

 

 

โœ” ์ŠคํŠธ๋ ˆ์Šค ํ…Œ์ŠคํŠธ ํˆด๋กœ ์„ฑ๋Šฅ ์ธก์ •ํ•˜๊ธฐ(by Artillery)

 NodeJS ์„ค์น˜ํ•˜๊ธฐ

nodejs.org/ko/

 

Node.js

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

nodejs.org

NodeJS ์„ค์น˜ ๊ฒฐ๊ณผ

 

 

 

 Visual Studio Code ์‹คํ–‰

artillery-scripts ๋ผ๋Š” ํด๋”๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ด ํด๋”๋ฅผ ์—ด์–ด์ค๋‹ˆ๋‹ค.

(์†Œ๋ฌธ์ž๋กœ ์ƒ์„ฑํ–ˆ๋Š”๋ฐ, ๋Œ€๋ฌธ์ž๋กœ ๋‚˜์˜ต๋‹ˆ๋‹ค.)

 

 

 

•Artillery ์‹คํ–‰

artillery.io/docs/guides/getting-started/installing-artillery.html#System-requirements

 

Installing Artillery | Artillery.io Documentation

What you’ll learn How to install Artillery via npm How to check that your Artillery installation is working System requirements Artillery is a CLI application that is installed on your computer. Artillery should run on any system that runs Node.js v12 or

artillery.io

 

 

 

 

Visual Studio Code์—์„œ ํ™”๋ฉด ์ƒ๋‹จ Terminal > New Terminal์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

(๋‹จ์ถ•ํ‚ค: Ctrl + Shift + `(์ˆซ์ž 1 ์ขŒ์ธก))

 

 

Terminal์ด ์—ด๋ฆฌ๋ฉด artillerty ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

npm install -g artillery

 

 

Artillery ์‚ฌ์ดํŠธ์—์„œ Core Concepts๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.

ํ™”๋ฉด์—์„œ ๋‚ด๋ ค๊ฐ€๋‹ค๋ณด๋ฉด ์œ„์™€ ๊ฐ™์ด ์ฝ”๋“œ๊ฐ€ ์กด์žฌํ•˜๋Š”๋ฐ์š”, ์œ„ ์ฝ”๋“œ๋ฅผ ๋ชจ๋‘ ๋ณต์‚ฌ ํ•œ ํ›„

Visual Studio Code์—์„œ yaml ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ , ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

 

 

GCP cpu-instance-1 ์ธ์Šคํ„ด์Šค์—์„œ Spring Boot ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋‹ค์‹œ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

 

Visual Studio Code์— ์ž‘์„ฑํ•œ yaml ํŒŒ์ผ์„ ์œ„์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

ํ•„์š”์—†๋Š” ๋ถ€๋ถ„์€ ๋ชจ๋‘ ์ œ๊ฑฐํ•˜๊ณ  target, phases, scenarios ๋ถ€๋ถ„๋งŒ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

    target: GCP์˜ ์™ธ๋ถ€ IP

    • phases: ํ…Œ์ŠคํŠธ ์„ฑ๋Šฅ ์„ค์ •

    scenarios: name ๋ฐ get๋ฐฉ์‹์˜ url ์„ค์ •

 

 

 

Visual Studio Code์˜ Terminal์—์„œ artillery์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

 

์œ„ ๊ณผ์ •์ด ๋๋‚˜๋ฉด report.json ์ด๋ผ๋Š” ํŒŒ์ผ์ด ์ƒ์„ฑ ๋ฉ๋‹ˆ๋‹ค.

 

 

์œ„ json ํŒŒ์ผ์„ html๋กœ ๋ณด๊ธฐ ์œ„ํ•ด ์œ„ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿผ ์œ„์™€ ๊ฐ™์€ artillery์˜ report ํ™”๋ฉด์ด ์‹คํ–‰์ด ๋ฉ๋‹ˆ๋‹ค.

 

 

Scenario counts์—์„œ ํ˜„์žฌ yamlํŒŒ์ผ์— ์„ค์ •ํ•œ duration์€ 60, arrivalRate์€ 1์ด๋ฏ€๋กœ

60 ๋ฒˆ์˜ Request๊ฐ€ ์ด๋ฃจ์–ด์ง„ ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

chart์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ทธ๋ž˜ํ”„ ์ค‘ ํ•˜๋‚˜์ธ๋ฐ์š”, yaml์— ์„ค์ •ํ•œ arrivalRate์˜ ๊ฐ’์„ ์ฆ๊ฐ€์‹œํ‚ค๋ฉด์„œ ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๊ณ ,

์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†์„๋•Œ๊นŒ์ง€ ์‹คํ–‰ํ•˜๋ฉฐ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.


 

โœ” ๊ณ  ์‚ฌ์–‘์˜ CPU๋กœ Scale-up ํ•˜๊ธฐ

๊ณ  ์‚ฌ์–‘์˜ CPU๋กœ Scale-up์„ ํ†ตํ•ด ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

GCP์—์„œ ๊ธฐ์กด์˜ cpu-instance-1 ์ธ์Šคํ„ด์Šค๋Š” ์‚ญ์ œํ•˜๊ณ  ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

 

๊ธฐ์กด๊ณผ ๋ชจ๋‘ ๋™์ผํ•˜๊ฒŒ ์„ค์ •ํ•˜๊ณ , ๋จธ์‹  ์œ ํ˜•์€ e2-highcpu-8 ๋กœ ์„ค์ •ํ•˜๊ณ  ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    • ์ด๋ฆ„: cpu-instance-1

    ๋ฆฌ์ „: asia-northeast3(์„œ์šธ)

    ๋จธ์‹  ์œ ํ˜•: e2-highcpu-8

    ๋ถ€ํŒ… ๋””์Šคํฌ: CentOS 7

    •๋ฐฉํ™”๋ฒฝ: HTTP, HTTPS ํŠธ๋ž˜ํ”ฝ ํ—ˆ์šฉ

 

 

์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜๋ฉด ์œ„์—์„œ ์ง„ํ–‰ํ•œ wget, Java ์„ค์น˜ ๋ฐ jar ํŒŒ์ผ ์‹คํ–‰์„ ๋™์ผํ•˜๊ฒŒ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 $ sudo yum install wget

 $ sudo yum install java

 

 

์ธ์Šคํ„ด์Šค์˜ ์™ธ๋ถ€ IP๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค๋ฉด cpu-test.yaml ํŒŒ์ผ์—๋„ ์™ธ๋ถ€ IP๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

์ˆ˜์ • ํ›„ artillery๋ฅผ ํ†ตํ•ด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

์ฐจํŠธ ํŽ˜์ด์ง€๋ฅผ ๋ณด๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

 

๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด ํ™•์‹คํžˆ ๊ณ ์„ฑ๋Šฅ CPU(highcpu-8) ์ด latency time(์ง€์—ฐ ์‹œ๊ฐ„)์ด ์งง์€ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

์œ„ ํ…Œ์ŠคํŠธ ๊ณผ์ •์ด ๋ชจ๋‘ ๋๋‚˜๋ฉด ์ข€์ „์— ์ƒ์„ฑํ•œ GCP ์ธ์Šคํ„ด์Šค๋Š” ๋ฐ˜๋“œ์‹œ ์‚ญ์ œ๋ฅผ ํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

(๊ณ ์„ฑ๋Šฅ CPU ์ด๋ฏ€๋กœ ๋น„์šฉ์„ ๋งŽ์ด ์ฐจ์ง€ํ•ฉ๋‹ˆ๋‹ค !)

 

 

 

โ€ป ์˜ˆ์ƒ TPS๋ณด๋‹ค ์—ฌ์œ ๋กญ๊ฒŒ ์žก์Šต๋‹ˆ๋‹ค.

โ€ป API์— ๊ธฐ๋Œ€ Latency๋ฅผ ๋งŒ์กฑํ•  ๋•Œ๊นŒ์ง€ ์„ฑ๋Šฅ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

โ€ป Scale-out์„ ํ•ด๋„ ์„ฑ๋Šฅ์ด ํ–ฅ์ƒ๋˜์ง€ ์•Š์œผ๋ฉด, ๋ณ‘๋ชฉ์„ ์˜์‹ฌํ•ด๋ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.(์ฝ”๋“œ, I/O ๋“ฑ๋“ฑ)

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€