0Pricing
Load Testing & Performance Benchmarking (JMeter & k6) · 강의

가상 사용자 시나리오(VU)

다양한 부하 패턴을 효과적으로 시뮬레이션하도록 여러 가상 사용자 시나리오를 정의하고 관리합니다.

가상 사용자 시나리오(VU)은(는) CoddyKit의 무료 Load Testing & Performance Benchmarking (JMeter & k6) 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Load Testing & Performance Benchmarking (JMeter & k6) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Beyond Simple Load: k6 Scenarios

When performance testing, a simple 'run 10 VUs for 30 seconds' might not capture real user behavior. Real users often have different patterns: some log in, some browse, some make purchases. This is where k6 scenarios come in!

Scenarios allow you to define complex load profiles and simulate diverse user groups, each with its own specific behavior and load pattern, all within a single test script.

Defining Your Test Scenarios

In k6, you define scenarios within the options object of your test script. The scenarios block is a JavaScript object where each key represents a unique scenario name.

Each scenario specifies an executor, which dictates how virtual users (VUs) and iterations are managed. It also links to a specific function in your script that defines what those VUs will do.

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    // Scenario definitions go here
  },
};

export default function () {
  http.get('https://test.k6.io');
  sleep(1);
}

Basic Scenario: Shared Iterations

The default k6 executor, shared-iterations, distributes a fixed number of iterations among a pool of VUs. Each VU will execute as many iterations as it can until the total specified iterations are complete or the test duration ends.

It's good for tests where you want to complete a specific amount of work.

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    my_scenario: {
      executor: 'shared-iterations',
      vus: 5,
      iterations: 20,
      maxDuration: '30s',
    },
  },
};

export default function () {
  http.get('https://test.k6.io');
  sleep(1);
}

Constant Load with `constant-VUs`

The constant-VUs executor maintains a fixed number of virtual users throughout the test's duration. VUs are started at the beginning and kept active until the duration is met.

This is useful for simulating a steady, continuous load on your system.

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    constant_load: {
      executor: 'constant-VUs',
      vus: 10,
      duration: '1m', // Run 10 VUs for 1 minute
    },
  },
};

export default function () {
  http.get('https://test.k6.io/news.php');
  sleep(2);
}

Gradual Load with `ramping-VUs`

The ramping-VUs executor allows you to gradually increase or decrease the number of virtual users over time. This simulates a more realistic load curve, like users slowly joining a website or leaving it.

It uses stages to define these changes in VU count.

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    gradual_load: {
      executor: 'ramping-VUs',
      startVUs: 0,
      stages: [
        { duration: '30s', target: 20 }, // Ramp up to 20 VUs over 30s
        { duration: '1m', target: 20 },  // Stay at 20 VUs for 1 minute
        { duration: '20s', target: 0 },  // Ramp down to 0 VUs over 20s
      ],
    },
  },
};

export default function () {
  http.get('https://test.k6.io/contacts.php');
  sleep(1);
}

Structuring Load with Stages

Within ramping-VUs, stages are an array of objects, each with a duration and a target VU count.

  • duration: How long this stage lasts (e.g., '1m', '30s').
  • target: The number of VUs to reach by the end of this stage. k6 will linearly ramp VUs from the current stage's end target to the next stage's target.

Stages are powerful for modeling complex load patterns like peak hours or sudden traffic spikes.

Controlling Request Rate: `ramping-arrival-rate`

Unlike VU-based executors, ramping-arrival-rate is an open model executor. It controls the rate at which new iterations (or 'arrivals') are started, rather than the number of VUs.

This is ideal for testing systems where you care about requests per second (RPS) or transactions per second (TPS).

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    arrival_rate_test: {
      executor: 'ramping-arrival-rate',
      startRate: 0, // Initial iterations per second
      timeUnit: '1s', // How often 'rate' is applied
      stages: [
        { duration: '30s', target: 10 }, // Ramp up to 10 iterations/s over 30s
        { duration: '1m', target: 10 },  // Stay at 10 iterations/s for 1 minute
      ],
      preAllocatedVUs: 20, // Initial VUs to allocate
      maxVUs: 50,         // Max VUs to spin up if needed
    },
  },
};

export default function () {
  http.get('https://test.k6.io/login.php');
  sleep(0.5); // Simulate some user think time
}

Combining Different User Behaviors

You can define multiple, independent scenarios within a single k6 script. Each scenario can have its own executor, VUs, duration, and even call a different function that defines its specific user journey.

This allows you to simulate a mix of user types (e.g., admin users, regular users, guests) in one comprehensive test.

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    anonymous_browsing: {
      executor: 'constant-VUs',
      vus: 5,
      duration: '30s',
      exec: 'anonymousBrowser', // Call this function
    },
    authenticated_user: {
      executor: 'ramping-VUs',
      startVUs: 0,
      stages: [{ duration: '20s', target: 3 }],
      exec: 'loggedInUser', // Call this function
    },
  },
};

export function anonymousBrowser() {
  http.get('https://test.k6.io/');
  sleep(2);
}

export function loggedInUser() {
  // Simulate login (not actual login, just for demo)
  http.post('https://test.k6.io/login', { username: 'user', password: 'pass' });
  sleep(1);
  http.get('https://test.k6.io/my-profile');
  sleep(2);
}

Fine-Tuning Scenario Execution

Beyond basic executor settings, scenarios offer additional options for precise control:

  • startTime: Delay the start of a specific scenario (e.g., '10s' after test start). Useful for staggered tests.
  • gracefulStop: How long k6 should wait for active VUs to finish their current iteration before forcefully stopping them (e.g., '5s').
  • env: Environment variables specific to this scenario.

These options help orchestrate complex test flows.

Scenario Challenge

You need to simulate a load test where:

  • 5 virtual users (VUs) constantly browse the homepage for 1 minute.
  • At the same time, another group of users gradually ramps up from 0 to 10 VUs over 30 seconds, then holds at 10 VUs for 30 seconds, performing a login action.

Which two k6 executors would be most appropriate for these two distinct user behaviors?

Scenarios: Your Load Orchestrator

In this lesson, you've learned how k6 scenarios enable you to model diverse and realistic load patterns. We explored key executors:

  • shared-iterations for fixed work.
  • constant-VUs for steady load.
  • ramping-VUs for gradual load changes with stages.
  • ramping-arrival-rate for open-model testing based on request rate.

You also saw how to combine multiple scenarios and use options like startTime for advanced control. Mastering scenarios is crucial for sophisticated performance testing!

자주 묻는 질문

“가상 사용자 시나리오(VU)” 강의는 무료인가요?

네 — “가상 사용자 시나리오(VU)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Load Testing & Performance Benchmarking (JMeter & k6) 강의 전체를 잠금 해제할 수 있습니다. Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 총 4개의 강의가 포함되어 있습니다.

“가상 사용자 시나리오(VU)”에서 뭘 배우나요?

다양한 부하 패턴을 효과적으로 시뮬레이션하도록 여러 가상 사용자 시나리오를 정의하고 관리합니다. 브라우저에서 직접 실행하는 실습 코드로 Load Testing & Performance Benchmarking (JMeter & k6)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Load Testing & Performance Benchmarking (JMeter & k6)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Load Testing & Performance Benchmarking (JMeter & k6)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“가상 사용자 시나리오(VU)” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Load Testing & Performance Benchmarking (JMeter & k6) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 가상 사용자 시나리오(VU)
  2. k6에서의 데이터 매개변수화
  3. k6를 활용한 클라우드 실행
  4. k6의 사용자 지정 메트릭 및 추세
← Load Testing & Performance Benchmarking (JMeter & k6)(으)로 돌아가기