config:
target: <http://localhost:3000>
phases:
- duration: 60
arrivalRate: 1
rampTo: 5
name: Warm up phase
- duration: 60
arrivalRate: 5
rampTo: 10
name: Ramp up load
- duration: 60
arrivalRate: 10
rampTo: 30
name: Spike phase
processor: './dist/create-dummy-onlineboard.js'
payload:
- path: './artillery/onlineboard.csv'
fields:
- 'title'
- 'content'
- path: './artillery/onlineboardcomment.csv'
fields:
- 'content'
defaults:
headers:
Cookie: 'authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwMSwiaWF0IjoxNzEyODE5NjE0LCJleHAiOjE3NTYwMTk2MTR9.HRyDR3Xk5VNs2_sLCsxtY2oFeWe24u0iVrvdU2eInlU'
ensure:
thresholds:
- http.response_time.p99: 100
- http.response_time.p95: 75
plugins:
ensure: {}
apdex: {}
metrics-by-endpoint: {}
scenarios:
- name: 'create online board'
flow:
- get:
url: '<http://localhost:3000/online-boards>'
- get:
url: '<http://localhost:3000/online-boards/1>'
- post:
url: '<http://localhost:3000/online-boards>'
json:
title: '{{$loopElement.title}}'
content: '{{$loopElement.content}}'
- name: 'create online board comment'
flow:
- get:
url: '<http://localhost:3000/online-boards/comments/1>'
- post:
url: '<http://localhost:3000/online-boards/comments/1>'
json:
content: '{{ $loopElement.content }}'
#'./artillery/onlineboard.csv'
title, content
제목1, 내용1
제목2, 내용2
제목3, 내용3
제목4, 내용4
제목5, 내용5
제목6, 내용6
제목7, 내용7
제목8, 내용8
제목9, 내용9
제목10, 내용10
# './artillery/onlineboardcomment.csv'
content
댓글1
댓글2
댓글3
댓글4
댓글5
댓글6
댓글7
댓글8
댓글9
댓글10
// create-dummy-onlineboard.ts
import { DataSource } from 'typeorm';
import { faker } from '@faker-js/faker';
import { Users } from './users/entities/user.entity';
import { UserInfos } from './users/entities/user-info.entity';
import { HumorsHallOfFame } from './humors/entities/humor_hall_of_fame.entity';
import { HumorLike } from './humors/entities/humor_like.entity';
import { HumorBoards } from './humors/entities/humor-board.entity';
import { OnlineBoardComments } from './online_board_comment/entities/online_board_comment.entity';
import { OnlineBoards } from './online_boards/entities/online_board.entity';
import { PolticalDebateComments } from './poltical_debates/entities/poltical_debate_comments.entity';
import { PolticalDebateBoards } from './poltical_debates/entities/poltical_debate.entity';
import { Trials } from './trials/entities/trial.entity';
import { OnlineBoardLike } from './online_boards/entities/online_board_like.entity';
import { Votes } from './trials/entities/vote.entity';
import { EachVote } from './trials/entities/Uservote.entity';
import { HumorComments } from './humor-comments/entities/humor_comment.entity';
import { TrialHallOfFames } from './trials/entities/trial_hall_of_fame.entity';
import { TrialLike } from './trials/entities/trials.like.entity';
import { HumorVotes } from './humors/entities/HumorVote.entity';
import { EachHumorVote } from './humors/entities/UservoteOfHumorVote.entity';
import { PolticalDebateVotes } from './poltical_debates/entities/polticalVote.entity';
import { EachPolticalVote } from './poltical_debates/entities/userVoteOfPoltical_debate.entity';
import { TrialsChat } from './events/entities/trialsChat.entity';
const AppDataSource = new DataSource({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'postgres',
database: 'optimization',
entities: [
Users,
UserInfos,
HumorsHallOfFame,
HumorLike,
HumorBoards,
HumorComments,
OnlineBoardComments,
OnlineBoards,
OnlineBoardLike,
PolticalDebateComments,
PolticalDebateBoards,
PolticalDebateVotes,
Trials,
TrialLike,
TrialsChat,
TrialHallOfFames,
Votes,
EachVote,
HumorVotes,
EachHumorVote,
EachPolticalVote,
],
synchronize: true,
logging: false,
});
async function getRandomUserId() {
const userRepository = AppDataSource.getRepository(Users);
const users = await userRepository.find();
const randomIndex = Math.floor(Math.random() * users.length);
return users[randomIndex].id; // 무작위로 하나의 사용자 ID 반환
}
async function createDummyData() {
await AppDataSource.initialize()
.then(async () => {
// 자유게시판 생성
for (let i = 0; i < 3; i++) {
console.log(
`==========[ Dummy Online Boards and Comments Data Creater Started ]==========`,
);
const userId = await getRandomUserId();
const onlineBoard = new OnlineBoards();
onlineBoard.title = faker.company.catchPhrase();
onlineBoard.content = faker.lorem.text();
onlineBoard.userId = userId;
const createOnlineBoard = await AppDataSource.manager.save(onlineBoard);
// 해당 자유게시판에 속하는 댓글 생성
for (let j = 0; j < 5; j++) {
const userId = await getRandomUserId();
const onlineBoardComment = new OnlineBoardComments();
onlineBoardComment.content = faker.lorem.sentence(1);
onlineBoardComment.onlineBoardId = onlineBoard.id;
onlineBoardComment.onlineBoard = onlineBoard;
onlineBoardComment.userId = userId;
const createComment =
await AppDataSource.manager.save(onlineBoardComment);
}
}
})
.catch((error) => console.log(error));
}
createDummyData();