Cassandra Stress

Cassandra Stress

cassandra-stress 도구는 더 이상 사용되지 않습니다(deprecated). Cassandra를 벤치마킹하는 더 나은 도구는 NoSQLBench예요.

cassandra-stress 도구는 Cassandra 클러스터를 벤치마킹하고 부하 테스트하는 데 사용합니다. cassandra-stress는 임의의 CQL 테이블과 쿼리 테스트를 지원하므로, 사용자가 자신의 데이터 모델을 벤치마킹할 수 있어요.

이 문서는 개인 스키마를 테스트하는 사용자 모드(user mode)에 초점을 맞춥니다.

출처: 문서

본문

사용법

여러 연산 유형이 있습니다:

  • 표준 데이터의 write-only, read-only, mixed 워크로드
  • 카운터 컬럼의 write-only 및 read-only 워크로드
  • 커스텀 스키마에서 커스텀 쿼리를 실행하는 사용자 구성 워크로드

문법은 cassandra-stress <command> [options]입니다. 특정 명령이나 옵션에 대한 자세한 정보는 cassandra-stress help <command|option>을 실행하세요.

명령은 다음과 같습니다:

read 여러 동시 읽기 - 클러스터는 먼저 쓰기 테스트로 채워져야 함

write 클러스터에 대한 여러 동시 쓰기

mixed 기본 명령들의 인터리빙, 구성 가능한 비율과 분포 - 클러스터는 먼저 쓰기 테스트로 채워져야 함

counter_write 카운터의 여러 동시 업데이트

counter_read 카운터의 여러 동시 읽기. 클러스터는 먼저 counterwrite 테스트로 채워져야 함

user 사용자 제공 쿼리의 인터리빙, 구성 가능한 비율과 분포

help 명령 또는 옵션에 대한 도움말 출력

print 분포 정의의 출력 검사

기본 옵션:

  • -pop: 모집단 분포 및 파티션 내 방문 순서
  • -insert: 배칭 및 파티션 업데이트 분할을 위한 다양한 방법과 관련된 특정 옵션 삽입
  • -col: 크기·개수 분포, 데이터 생성기, 이름, 비교자, 슈퍼 컬럼 사용 여부 같은 컬럼 세부 사항
  • -rate: 스레드 수, 속도 제한 또는 자동 모드(기본값은 auto)
  • -mode: 인증 및 연결 속성에 대한 추가 옵션. 또한 "simplenative"는 독립 Java 드라이버의 대안으로 선택할 수 있음
  • -errors: 스트레스 중 오류 발생 시 처리 방법
  • -sample: 지연 시간 측정을 위해 수집할 샘플 수 지정
  • -schema: 복제 설정, 압축, 컴팩션 등
  • -node: 연결할 노드
  • -log: 진행 상황을 기록할 위치와 그 간격
  • -transport: 커스텀 전송 팩토리
  • -port: cassandra 노드에 연결할 포트
  • -graph: 기록된 메트릭 그래프
  • -tokenrange: 토큰 범위 설정
  • -jmx: JMX 연결을 위한 사용자 이름과 비밀번호
  • -credentials-file <path>: CQL, JMX, 전송을 위해 지정할 자격 증명 파일
  • -reporting: 스트레스 출력을 위한 통계 및 헤더 인쇄 빈도

하위 옵션

모든 명령과 기본 옵션에는 자체 하위 옵션 모음이 있습니다. 여기서 나열하기에는 너무 많아요. 각 명령 또는 옵션의 하위 옵션에 대한 정보는 help 명령 cassandra-stress help <command|option>을 사용하세요.

사용자 모드 (User mode)

사용자 모드를 사용하면 자신의 스키마를 스트레스 테스트하여 장기적으로 시간을 절약할 수 있어요. 애플리케이션이 스키마로 스트레스 테스트를 사용해 확장될 수 있는지 알아보세요.

프로필 (Profile)

사용자 모드는 YAML로 프로필을 정의합니다. 여러 YAML 파일을 지정할 수 있으며, 이 경우 ops 인수의 연산은 specname.opname으로 참조됩니다.

프로필 식별자:

specname: staff_activities

테스트용 키스페이스:

keyspace: staff

키스페이스용 CQL. 키스페이스가 이미 존재하면 선택사항:

keyspace_definition: |
 CREATE KEYSPACE stresscql WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};

스트레스 대상 테이블:

table: staff_activities

테이블용 CQL. 테이블이 이미 존재하면 선택사항:

table_definition: |
  CREATE TABLE staff_activities (
      name text,
      when timeuuid,
      what text,
      PRIMARY KEY(name, when, what)
  )

위 테이블에서 생성된 컬럼에 대한 선택적 메타 정보. min과 max는 text와 blob 타입에만 적용됩니다. distribution 필드는 해당 컬럼의 행 전체에 걸친 총 고유 모집단 분포를 나타냅니다:

columnspec:
  - name: name
    size: uniform(5..10) # The names of the staff members are between 5-10 characters
    population: uniform(1..10) # 10 possible staff members to pick from
  - name: when
    cluster: uniform(20..500) # Staff members do between 20 and 500 events
  - name: what
    size: normal(10..100,50)

지원되는 타입은:

범위 [min..max]에 대한 지수 분포:

EXP(min..max)

범위 [min..max]에 대한 극한값(Weibull) 분포:

EXTREME(min..max,shape)

평균=(min+max)/2, 표준편차=(mean-min)/stdvrng인 가우시안/정규 분포:

GAUSSIAN(min..max,stdvrng)

평균과 표준편차가 명시적으로 정의된 가우시안/정규 분포:

GAUSSIAN(min..max,mean,stdev)

범위 [min, max]에 대한 균일 분포:

UNIFORM(min..max)

항상 같은 값을 반환하는 고정 분포:

FIXED(val)

~가 앞에 붙으면 분포가 반전됩니다.

모든 컬럼의 기본값은 size: uniform(4..8), population: uniform(1..100B), cluster: fixed(1)입니다.

삽입 분포:

insert:
  # How many partition to insert per batch
  partitions: fixed(1)
  # How many rows to update per partition
  select: fixed(1)/500
  # UNLOGGED or LOGGED batch for insert
  batchtype: UNLOGGED

현재 모든 삽입은 배치 안에서 이루어집니다.

테스트 중 사용할 읽기 문:

queries:
   events:
      cql: select *  from staff_activities where name = ?
      fields: samerow
   latest_event:
      cql: select * from staff_activities where name = ?  LIMIT 1
      fields: samerow

사용자 모드 테스트 실행:

cassandra-stress user profile=./example.yaml duration=1m "ops(insert=1,latest_event=1,events=1)" truncate=once

이 명령은 스키마를 만든 뒤 1분 동안 동일한 수의 insert, latest_event 쿼리, events 쿼리로 테스트를 실행합니다. 또한 테스트 전에 테이블을 한 번 잘라냅니다(truncate).

전체 예제는 여기서 찾을 수 있습니다:

spacenam: example # idenitifier for this spec if running with multiple yaml files
keyspace: example

# Would almost always be network topology unless running something locally
keyspace_definition: |
  CREATE KEYSPACE example WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};

table: staff_activities

# The table under test. Start with a partition per staff member
# Is this a good idea?
table_definition: |
  CREATE TABLE staff_activities (
        name text,
        when timeuuid,
        what text,
        PRIMARY KEY(name, when)
  )

columnspec:
  - name: name
    size: uniform(5..10) # The names of the staff members are between 5-10 characters
    population: uniform(1..10) # 10 possible staff members to pick from
  - name: when
    cluster: uniform(20..500) # Staff members do between 20 and 500 events
  - name: what
    size: normal(10..100,50)

insert:
  # we only update a single partition in any given insert
  partitions: fixed(1)
  # we want to insert a single row per partition and we have between 20 and 500
  # rows per partition
  select: fixed(1)/500
  batchtype: UNLOGGED             # Single partition unlogged batches are essentially noops

queries:
   events:
      cql: select *  from staff_activities where name = ?
      fields: samerow
   latest_event:
      cql: select * from staff_activities where name = ?  LIMIT 1
      fields: samerow

여러 yaml 파일로 사용자 모드 테스트 실행:

cassandra-stress user profile=./example.yaml,./example2.yaml duration=1m "ops(ex1.insert=1,ex1.latest_event=1,ex2.insert=2)" truncate=once

이 명령은 example.yaml과 example2.yaml 파일에 지정된 대로 연산을 실행합니다. example.yaml과 example2.yaml은 같은 테이블을 참조할 수 있지만, 테이블 정의가 동일해야 한다는 점에 주의해야 합니다(데이터 생성 사양은 다를 수 있어요).

라이트웨이트 트랜잭션 지원

cassandra-stress는 라이트웨이트 트랜잭션(lightweight transaction)을 지원합니다. 이 기능을 사용하려면 명령이 먼저 Cassandra에서 현재 데이터를 읽은 다음, 읽은 값을 사용해 라이트웨이트 트랜잭션 조건을 충족합니다.

라이트웨이트 트랜잭션 업데이트 쿼리:

queries:
  regularupdate:
      cql: update blogposts set author = ? where domain = ? and published_date = ?
      fields: samerow
  updatewithlwt:
      cql: update blogposts set author = ? where domain = ? and published_date = ? IF body = ? AND url = ?
      fields: samerow

전체 예제는 여기서 찾을 수 있습니다:

# Keyspace Name
keyspace: stresscql

# The CQL for creating a keyspace (optional if it already exists)
# Would almost always be network topology unless running something locall
keyspace_definition: |
  CREATE KEYSPACE stresscql WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};

# Table name
table: blogposts

# The CQL for creating a table you wish to stress (optional if it already exists)
table_definition: |
  CREATE TABLE blogposts (
        domain text,
        published_date timeuuid,
        url text,
        author text,
        title text,
        body text,
        PRIMARY KEY(domain, published_date)
  ) WITH CLUSTERING ORDER BY (published_date DESC)
    AND compaction = { 'class':'LeveledCompactionStrategy' }
    AND comment='A table to hold blog posts'

### Column Distribution Specifications ###

columnspec:
  - name: domain
    size: gaussian(5..100)       #domain names are relatively short
    population: uniform(1..10M)  #10M possible domains to pick from

  - name: published_date
    cluster: fixed(1000)         #under each domain we will have max 1000 posts

  - name: url
    size: uniform(30..300)

  - name: title                  #titles shouldn't go beyond 200 chars
    size: gaussian(10..200)

  - name: author
    size: uniform(5..20)         #author names should be short

  - name: body
    size: gaussian(100..5000)    #the body of the blog post can be long

### Batch Ratio Distribution Specifications ###

insert:
  partitions: fixed(1)            # Our partition key is the domain so only insert one per batch

  select:    fixed(1)/1000        # We have 1000 posts per domain so 1/1000 will allow 1 post per batch

  batchtype: UNLOGGED             # Unlogged batches

#
# A list of queries you wish to run against the schema
#
queries:
   singlepost:
      cql: select * from blogposts where domain = ? LIMIT 1
      fields: samerow
   regularupdate:
      cql: update blogposts set author = ? where domain = ? and published_date = ?
      fields: samerow
   updatewithlwt:
      cql: update blogposts set author = ? where domain = ? and published_date = ? IF body = ? AND url = ?
      fields: samerow

그래프 (Graphing)

각 스트레스 실행에 대해 그래프를 생성할 수 있어요.

새 그래프를 만들려면:

cassandra-stress user profile=./stress-example.yaml "ops(insert=1,latest_event=1,events=1)" -graph file=graph.html title="Awesome graph"

기존 그래프에 새 실행을 추가하려면 기존 파일을 가리키고 개정 이름을 추가하세요:

cassandra-stress user profile=./stress-example.yaml duration=1m "ops(insert=1,latest_event=1,events=1)" -graph file=graph.html title="Awesome graph" revision="Second run"

FAQ

키스페이스에 NetworkTopologyStrategy를 어떻게 사용하나요?

schema 옵션을 사용하고 괄호를 이스케이프하거나 따옴표로 감싸세요:

cassandra-stress write -schema "replication(strategy=NetworkTopologyStrategy,datacenter1=3)"

SSL은 어떻게 사용하나요?

transport 옵션을 사용하세요:

cassandra-stress "write n=100k cl=ONE no-warmup" -transport "truststore=$HOME/jks/truststore.jks truststore-password=cassandra"

Cassandra Stress는 보안 도구인가요?

Cassandra stress는 보안 도구가 아닙니다. 직렬화 및 도구의 다른 측면은 어떤 보안 보장도 제공하지 않아요.

더 알아보기 (Learn more)