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

CPU๋ฅผ ๊ทน๋‹จ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ

by sangyunpark99 2024. 8. 28.

๐Ÿ“ ํ•ด๋‹น ๊ธ€์€ ํ˜„์ง ๋Œ€๊ธฐ์—… ๊ฐœ๋ฐœ์ž ํ‘ธ์™€ ํ•จ๊ป˜ํ•˜๋Š” ์ง„์งœ ๋ฐฑ์—”๋“œ ์‹œ์Šคํ…œ ์‹ค๋ฌด! ๊ฐ•์˜๋ฅผ ์ˆ˜๊ฐ•ํ•˜๊ณ  ๋‚ด์šฉ์„ ์š”์•ฝํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค.

 

๐Ÿ”Ž ์ฝ”๋“œ ์ž‘์„ฑ

CPU๋ฅผ ๊ทน๋‹จ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์˜€๋‹ค.

package class101.foo.cpu;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.DatatypeConverter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

@RestController
public class HashController {

    @RequestMapping("/hash/{input}")
    public String getDigest(@PathVariable("input") String input) throws NoSuchAlgorithmException {
        for(int i = 0; i < 100_000; i++) {
            input = getMD5Digest(input);
        }
        return input;
    }

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

    private String getMD5Digest(String input) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(input.getBytes());
        byte[] digest = md.digest();
        String myHash = DatatypeConverter
                .printHexBinary(digest).toUpperCase();

        return myHash;
    }
}

 

API๋ฅผ ์š”์ฒญ์‹œ์— ๋“ค์–ด์˜จ input๊ฐ’์„ 10๋งŒ๋ฒˆ MD5 ํ•ด์‹œํ™”๋ฅผ ํ•ด์ฃผ๊ณ  ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค.

 

๐Ÿ”Ž ์„œ๋ฒ„ ์‹คํ–‰

 

application.propertise

server.port = 80

 

 

๐Ÿ”Ž GCP์— ๋ฐฐํฌํ•˜๋ ค๋‹ค๊ฐ€ AWS์— ๋ฐฐํฌํ•˜๊ธฐ

.jar ํŒŒ์ผ๋กœ ๋นŒ๋“œํ•œ ํ›„, GCP์— ๋ฐฐํฌํ•ด์ค€๋‹ค.

 

๐Ÿ’ฅ wget์„ ๋‹ค์šด ๋ฐ›๋Š”๋ฐ ๋‹ค์šด์ด ์•ˆ๋˜๋Š” ์ด์Šˆ๋กœ, AWS EC2๋กœ ํ”Œ๋žซํผ์„ ์˜ฎ๊ฒจ์ฃผ์—ˆ๋‹ค.

 

AWS EC2๋ฅผ ์ƒ์„ฑํ•˜๊ณ , github๊ณผ ssh๋ฅผ ์—ฐ๋™ํ•ด์ค€ ๋’ค, ssh๋ฅผ ์ด์šฉํ•ด์„œ ๋นŒ๋“œํ•ด์ค€ cpu-0.0.1-SNAPSHOT.jar ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ํ•ด์ฃผ์—ˆ๋‹ค.

์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๊ณ , ์ ‘์†์ด ์ •์ƒ์ ์œผ๋กœ ์ž˜ ๋˜๋Š”์ง€ ํ™•์ธํ•ด ์ฃผ์—ˆ๋‹ค.

 

 

๐Ÿ”Ž ์‹คํ–‰ ์†๋„ ํ™•์ธ

์•ฝ 66ms๊ฐ€ ๊ฑธ๋ ธ๋‹ค.

 

๐Ÿ”Ž Artillery ํ…Œ์ŠคํŠธ ํˆด๋กœ ์„ฑ๋Šฅ ์ธก์ •ํ•˜๊ธฐ

node.js ๊ธฐ๋ฐ˜์˜ Artillery๋ฅผ ๋‹ค์šด๋ฐ›์•„ ์ฃผ์—ˆ๋‹ค.

 

์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ๊ณต์‹๋ฌธ์„œ์— ๋‚˜์™€์žˆ๋Š” Run Your First Test ๋ชฉ์ฐจ๋ฅผ ์ฐธ๊ณ ํ–ˆ๋‹ค.

https://www.artillery.io/docs/get-started/core-concepts

 

Welcome – Artillery Docs

Learn how to get up and running with Artillery with reference docs, guides, tutorials and other resources

www.artillery.io

config:
  target: http://[aws ์ธ์Šคํ„ด์Šค ์ฃผ์†Œ ์ž…๋ ฅ]
  phases:
    - duration: 60
      arrivalRate: 1
      name: warm up
scenarios:
  - flow:
      - get:
          url: "/hash/123"

 

๊ณต์‹๋ฌธ์„œ์— ์˜ํ•˜๋ฉด duration๊ณผ arrivalRate๊ฐ€ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 

300์ดˆ ๋™์•ˆ ์ง€์†๋˜๋Š” ๋กœ๋“œ ๋‹จ๊ณ„๋กœ ๋งค์ดˆ๋งˆ๋‹ค 10๋ช…์˜ ์ƒˆ๋กœ์šด ๊ฐ€์ƒ ์‚ฌ์šฉ์ž๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

 

๋‚ด๊ฐ€ ์ ์šฉํ•œ json์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

60์ดˆ ๋™์•ˆ ์ง€์†๋˜๋Š” ๋กœ๋“œ ๋‹จ๊ณ„๋กœ ๋งค์ดˆ๋งˆ๋‹ค 1๋ช…์˜ ์ƒˆ๋กœ์šด ๊ฐ€์ƒ ์‚ฌ์šฉ์ž๊ฐ€ ์‹คํ–‰๋œ๋‹ค.

 

 

์‹คํ–‰ํ•ด์„œ ๋‚˜์˜จ json๊ธฐ๋ฐ˜์˜ ๊ฒฐ๊ณผ๋ฅผ html ๊ธฐ๋ฐ˜์˜ ๊ฒฐ๊ณผ๋กค ๋ณ€ํ™˜ํ•ด์ฃผ์—ˆ๋‹ค.

https://www.artillery.io/docs/reference/cli/report

 

Welcome – Artillery Docs

Learn how to get up and running with Artillery with reference docs, guides, tutorials and other resources

www.artillery.io

 

Json์œผ๋กœ ์„ฑ๋Šฅํ…Œ์ŠคํŠธ๋ฅผ ๊ธฐ๋กํ•˜๊ณ , ๊ธฐ๋กํ•œ ์„ฑ๋Šฅ ํ…Œ์ŠคํŠธ json์„ html๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ํ๋ฆ„์„ ๊ฐ€์ง„๋‹ค.

 

๐Ÿ”Ž HTML๋กœ ๋ณด๊ธฐ ์‰ฝ๊ฒŒ ๋ณ€๊ฒฝํ•œ ๊ทธ๋ž˜ํ”„

arrivalRate: 1

์‘๋‹ต ์ตœ๋Œ€ ์‹œ๊ฐ„์ด 101ms๊ฐ€ ๋œ๋‹ค.

 

๐Ÿ”Ž Arrival Rate๋ฅผ ์กฐ์ ˆํ•˜๋ฉด์„œ ๋ถ€ํ•˜์ฃผ๊ธฐ

์ œ์ผ ์ค‘์š”ํ•œ ์ง€ํ‘œ๋Š” ์‘๋‹ต์‹œ๊ฐ„์ด๋ผ๊ณ  ์ƒ๊ฐํ•ด์„œ, ์‘๋‹ต ์‹œ๊ฐ„์˜ ์ง€ํ‘œ๋ฅผ ๋น„๊ตํ•ด๋ณด์•˜๋‹ค.

๊ฐ„๋‹จํ•˜๊ฒŒ max ์ง€ํ‘œ๋งŒ ๋น„๊ตํ•ด ๋ณด์ž

 

โญ๏ธ arrival Rate๊ฐ€ 1์ธ ๊ฒฝ์šฐ, ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ธฐ

 

 

โญ๏ธ arrival Rate๋ฅผ 4์ธ ๊ฒฝ์šฐ, ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ธฐ

์‘๋‹ต ์ตœ๋Œ€ ์‹œ๊ฐ„์ด 180ms๊ฐ€ ๋œ๋‹ค.

 

โญ๏ธ arrival Rate๋ฅผ 10์œผ๋กœ ๋Š˜๋ฆฐ ํ›„, ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ธฐ

์‘๋‹ต ์ตœ๋Œ€ ์‹œ๊ฐ„์ด 190ms๊ฐ€ ๋œ๋‹ค.

 

 

arrival Rate์ˆ˜๋ฅผ ๋Š˜๋ฆด ์ˆ˜๋ก ์‘๋‹ต ์‹œ๊ฐ„์˜ ์ตœ๋Œ“๊ฐ’์ด ์ฆ๊ฐ€ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๐Ÿ”Ž ์‹ค๋ฌด์—์„œ ์„ฑ๋Šฅ ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๋Š” ๋ฐฉ๋ฒ•

- ์˜ˆ์ƒ TPS๋ณด๋‹ค ์—ฌ์œ ๋กญ๊ฒŒ

- ๊ธฐ๋Œ€ Latency๋ฅผ ๋งŒ์กฑํ•  ๋•Œ๊นŒ์ง€

- Scale-out์„ ํ•ด๋„ ์„ฑ๋Šฅ์ด ๋Š˜์ง€ ์•Š์œผ๋ฉด ๋ณ‘๋ชฉํ˜„์ƒ ์˜์‹ฌ

 

๐Ÿ”Ž ์šฉ์–ด ์ •๋ฆฌ

โ“TPS : Transaction Per Second์˜ ์•ฝ์ž, 1์ดˆ๋‹น ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ํŠธ๋žœ์žญ์…˜

๊ณ„์‚ฐ ๋ฐฉ๋ฒ• : ๊ตฌ๊ฐ„ ๋‚ด์˜ ํŠธ๋žœ์žญ์…˜ ์ˆ˜(transaction) / ๊ตฌ๊ฐ„ ์ดˆ(sec)

โ“Latency : ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ ํŒจํ‚ท์ด ์ถœ๋ฐœ์ง€์—์„œ ๋„์ฐฉ์ง€๊นŒ์ง€ ๊ฐ€๋Š” ๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„

โ“๋ณ‘๋ชฉ ํ˜„์ƒ : ์‹œ์Šคํ…œ์˜ CPU๋‚˜ ๋ฉ”๋ชจ๋ฆฌ, ๋””์Šคํฌ ๋“ฑ์˜ ์ž์› ์ค‘ ํ•˜๋‚˜๊ฐ€ ๋‹ค๋ฅธ ์ž์›๋“ค์— ๋น„ํ•ด ์ฒ˜๋ฆฌ ์†๋„๊ฐ€ ๋Š๋ ค์„œ, ์ „์ฒด์ ์ธ ์„ฑ๋Šฅ์„ ์ œํ•œํ•˜๋Š” ๊ฒฝ์šฐ