<aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/63a5d9b5-535f-44e9-abf4-96144aa19da1/ac867e9f-0a0a-4834-a19a-6ee75b60dc81/Group.svg" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/63a5d9b5-535f-44e9-abf4-96144aa19da1/ac867e9f-0a0a-4834-a19a-6ee75b60dc81/Group.svg" width="40px" /> Git을 사용하다 자주 만날 수 있는 상황을 문제로 풀면서 Git을 학습하는 서비스
</aside>
flowchart TD
A[Client] -->|HTTP req| B[Nest Server]
B --> |HTTP res|A
B --> |SSH|C[Container Server] --> |SSH|B
Nest 서버가 요청하는 대부분의 명령의 형태
docker exec ContainerName git status
이러한 명령의 결과를 받아오기 위해서는 SSH가 최선의 선택이라고 믿었다…!
docker exec
vs SSH
누가 우리 서비스의 병목인가?
SSH의 경우 SSH Pool을 구현하여 초기 연결 시간을 아낄 수 있었다
평균 300ms까지 개선했으며, 여전히 ssh에서만 200ms를 차지하는 것으로 판명
docker exec의 경우 exec 내부의 명령에 따라 크게 달랐다
git status
vs git clone
의 경우 당연히 전자가 빠르다
특히 node.js를 이용하면 아주 빠른 구현이 가능하기 때문에, 얼마 남지 않은 기간임에도 빠르게 도입 가능
마치 SSH 접속을 한 것처럼 body의 명령을 실행하는 서버
const express = require('express');
const { exec } = require('child_process');
const app = express();
app.use(express.json());
app.post('/', (req, res) => {
const command = req.body.command;
exec(command, (error, stdout, stderr) => {
res.json({ stdoutData: stdout, stderrData: stderr });
});
});
app.post('/cron', (req, res) => {
const command = req.body.command;
exec(command);
res.json({});
});
const port = 8080;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
“가장 이상적인 상황”에서 100ms대까지 개선