Terminologies

A few terms are used in Kafka you need to know.

  • Message: A stream of bytes. For simplicity, assume it as a string.
  • Producer: The application or client that produces messages which will be consumed by other clients.
  • Consumer: A client who receives the messages produced by the producers.
  • Broker: Receives the messages, stores it, and decides the consumers who should get these messages.
  • Topic: A unique name through which the data is streamed.
  • Partition: A Partition is a virtual division which allows parallelizing a topic by splitting the data in a particular topic across multiple brokers. A topic can have multiple partitions. Minimum of 1.
  • Offset: A unique number for a message in a topic’s partition.
  • Consumer Group: A group of consumers.
  • Leader: The responsible unit for the topic’s partitions to store messages.
  • Replica: The mirror/sync of your data to handle the faults. So that the data doesn’t get lost.
  • In-Sync Replica(ISR) (Replication Group): The in-sync replicas are replicas that are alive and are in sync with the leader.

 

중요 포인트

  • 토픽으로 통하는 모든 데이터의 read/write는 오직 리더와 이루어진다.
  • ISR 내의 모든 follower들은 누구라도 리더가 될 수 있다.
  • 자신이 읽고 있는 파티션에는 같은 그룹내 다른 컨슈머가 읽을 수 없다.
  • 한번 늘린 파티션은 절대로 줄일 수 없기 때문에 운영중에 파티션을 늘리는 것은 충분히 고려해야한다.
  • 파티션에 순차적으로 메세지가 쓰여지지 않는다. 곧 컨슈머가 메세지를 순서대로 읽지 못할수있다.
  • 파티션 개수 >= 컨슈머 개수
  • 여러개의 컨슈머 그룹은 동일한 레코드를 받는다. 이때 각 컨슈머 그룹마다 별도로 오프셋 관리를 한다.

 

토픽, 리플리케이션 팩터, 카프카 클러스터 한눈에 정리

Topic Peter-Topic01 Peter-Topic02
파티션 수 2 2
레플리케이션 팩터 3 2
브로커 수 3 3

토픽의 파티션 리더의 위치를 유심히 보자
Kafka replication example
파티션 개수는 컨슈머 개수보다 크거나 같다

Offset 이란?

Partition 의 특정 Consumer 가 메세지를 읽어들인 위치를 나타냄. Consumer 가 메세지 수신 처리를 재개할 때 어떤 메세지 부터 가져 가야 하는 지 알 수 있음.

 

Offset Topic

Kafka 에는 Consumer 의 offset 을 저장 하는 topic 이 존재함. (v0.9 release)

  • __consumer_offsets
    • 일반 토픽처럼 partitioning, replication 되어 있음(offsets.topic.replication.factor=1 (default=1)
      • Consumer 가 Kafka에 현재까지 읽은 메세지의 offset 정보를 알려주는 것을 commit 이라 한다.

 

 

'빅데이터 > Kafka Cluster' 카테고리의 다른 글

Kafka restart과 retention  (0) 2022.02.28
Kafka 스트레스 테스트  (0) 2022.02.28
Kafka Consumer/Producer  (0) 2022.02.28
Kafka 자주 사용하는 명령  (0) 2022.02.28
Kafka cluster failover  (0) 2022.02.28

Kafka에서는 토픽별로 leader와 follower가 존재한다.

토픽으로 통하는 모든 데이터의 read/write는 오직 leader와 이루어진다. leader가 다운되거나 leader가 있는 브로커가 다운된다면 flower 중의 하나가 leader가 된다.  이때, 일시적으로 follower가 leader가 되는 과정에서 read/write의 timeout이 발생할 수 있겠지만, retry가 일어나면 new leader와 read/write가 가능하기 때문에 장애 상황을 피할 수 있다.

 

ISR(In Sync Replica)

topic이 생성되고 옵션으로 replication factor를 설정하면 replication factor 수에 맞추어 ISR이 구성된다. 

leader : follower 중에서 자신보다 일정시간 동안 뒤쳐지면 leader가 될 자격이 없다고 판단하여 뒤쳐지는 follwer를 ISR에서 제외

follower : leader와 동일한 데이터 내용을 유지하기 위해서 짧은 주기로 leader로부터 데이터를 가져온다.

 

All down

1. 마지막까지 leader였던 broker1번이 up이 되고 다시 leader가 될 때까지 기다린다.

2. (default)ISR과 상관없이 누구라도 가장 빨리 up이 되는 topic이 leader가 된다(데이터 손실이 되더라도 장애 대응이 빠르다)


출처 : https://www.popit.kr/kafka-%EC%9A%B4%EC%98%81%EC%9E%90%EA%B0%80-%EB%A7%90%ED%95%98%EB%8A%94-topic-replication/

'빅데이터 > Kafka Cluster' 카테고리의 다른 글

Kafka restart과 retention  (0) 2022.02.28
Kafka 스트레스 테스트  (0) 2022.02.28
Kafka Consumer/Producer  (0) 2022.02.28
Kafka 자주 사용하는 명령  (0) 2022.02.28
Kafka Overview  (0) 2022.02.28

Redis configuration example

cat redis.conf 
port 6379
cluster-enabled yes
cluster-config-file /data/nodes.conf
cluster-node-timeout 5000
appendonly yes
appendfilename appendonly.aof
dbfilename dump.rdb
logfile /data/log.log

 

cluster-require-full-coverage

yes(default) : slave가 없는 master 노드가 다운되면 cluster 전체가 중지

no : slave가 없는 master 노드가 다운되더라도 cluster는 유지. 다만, 절반 이상의 노드가 다운되면 클러스터는 중지

데이터의 정합성이 중요하다면 yes, 일부 데이터가 유실되어도 괜찮으면 no

cluster-enabled

yes로 하면 cluster mode, no(default)로 하면 standalone mode

cluster-config-file 

클러스터의 상태가 변경될때 마다 상태를 기록

k exec -it redis-cluster-1 -- cat nodes.conf
d4c101ecd86542797df077d945f0329e55cfcd95 10.244.4.73:6379@16379 master - 0 1643072438406 3 connected 10923-16383
dc22da80db3ed3e4f956a53dbe3d527d72c56e87 10.244.4.71:6379@16379 master - 1643072438398 1643072438382 1 connected 0-5460
6a8fbdafa9f4fb0c5f3fa1c0bb943a2b2dc72f5d 10.244.4.77:6379@16379 master - 0 1643072438406 7 connected 5461-10922
c0ffb0eb52b8973a9f321cb6c5559a1b45ed304e 10.244.3.32:6379@16379 myself,slave 6a8fbdafa9f4fb0c5f3fa1c0bb943a2b2dc72f5d 0 1643072438381 7 connected
d197cc2d30c43780a8854bbd75c200c00ea5b417 10.244.4.74:6379@16379 slave d4c101ecd86542797df077d945f0329e55cfcd95 1643072438398 1643072438381 3 connected
85d745b2ff1f791fd5a81b1ba7710a1087ce844f 10.244.4.75:6379@16379 slave dc22da80db3ed3e4f956a53dbe3d527d72c56e87 1643072438398 1643072438382 1 connected
vars currentEpoch 7 lastVoteEpoch 0

cluster-node-timeout(millisecond)

레디스 노드가 다운되었는지 판단하는 시간(default: 15000)

cluster-slave-validity-factor

cluster 노드 다운시 해당 노드의 slave 노드를 마스터로 변경하는 장애 조치를 시작한다. 이때 마스터 노드와 slave 노드 간의 체크가 오랫동안 단절된 상태면 해당 slave는 승격 대상에서 제외된다. 이때 승격 대상에서 제외하는 파단 기준의 시간을 설정한다(default: 10)

계산식 : (cluster-node-timeout * cluster-slave-validity-factor) + repl-ping-slave-period

 

If set to zero, a replica will always consider itself valid, and will therefore always try to failover a master, regardless of the amount of time the link between the master and the replica remained disconnected.

port

방화벽을 사용하고 있다면 기본 포트에 10000을 더한 클러스터 버스 포트도 열려있어야 한다. 예를 들어 기본 포트로 6379를 사용한다면 16379번 포트도 같이 열어야 한다.

daemonize & logfile

no(default) : foreground

yes : background -> 리눅스 프롬프트가 바로 떨어짐(pidfile에 프로세스 id가 저장된다). log file을 지정해서 레디스 서버 로그를 기록하지 않으면 메시지가 날아간다.

 

백업 방식, AOF & RDB 

AOF는 명령이 실행될때 마다 기록되는 파일로서 데이터의 손실이 거의 없다.

RDB 파일은 특정한 간격마다 메모리에 있는 레디스 데이터 전체를 디스크에 쓴다.

  • RDB는 특정 시점의 메모리에 있는 데이터 전체를 바이너리 파일로 저장하는 것이다.
    AOF 파일보다 사이즈가 작다. 따라서 로딩 속도가 AOF 보다 빠르다.
    일반적으로 AOF 가 10초 걸린다면, RDB는 7초 정도로 생각하면 될 것이다.

*AOF를 기본으로 하고, RDB를 Option으로 하는 것을 권장.

*AOF와 RDB 파일 양쪽이 모두 존재할 경우 appendonly yes인 경우에는 레디스 서버 시작시 AOF 파일을 읽어 들이고, no인 경우 RDB 파일을 읽어들인다.

 

AOF configuration

appendonly(default: no)

장애 발생시 메모리에 기록된 데이터가 증발되는데 복구가 가능하도록 디스크에 쓰기 작업을 한다. 기본값으로 appendonly.aof 파일에 기록된다.

 

appendfsync

- always : 명령어 실행시마다 기록

- everysec(default) : 데이터를 모아 1초마다 디스크에 기록

- no : os에 쓰기 시점 처리를 위임

 

auto-aof-rewrite-percentage(0 - 100)

Default : 100

AOF 파일 사이즈가 숫자값 % 이상으로 커지면 rewrite 한다. %의 기준은 레디스 서버가 시작할 시점의 AOF 파일 사이즈를 기준으로 한다. Rewrite를 하면 rewirte 후 파일 사이즈를 기준으로 다시 계산한다.

 

auto-aof-rewrite-min-size

Default : 64mb

AOF 파일 사이즈가 64mb 이하면 rewrite를 하지 않는다. 파일 크기가 작은 경우 rewrite가 자주 발생하는 것을 방지

 

RDB configuration

dbfilename

RDB 파일명을 지정한다.

save

RDB 저장 시점을 지정할 수 있다. number of key modifications per second (Defaut : 900 1)


- http://redisgate.kr/redis/configuration/persistence.php

- https://programmer.help/blogs/redis-configuration-master-slave-cluster.html

- https://redis.io/topics/cluster-tutorial

'빅데이터 > Redis Cluster' 카테고리의 다른 글

Redis 주요 명령어  (0) 2022.02.08
Lettuce Configuration(RedisTemplate)  (0) 2022.02.08
Redis Cluster 장애 복구  (0) 2022.02.08
Redis Cluster Overview  (0) 2022.02.08

cluster nodes

 k exec -it redis-cluster-1 -- redis-cli cluster nodes
d4c101ecd86542797df077d945f0329e55cfcd95 10.244.4.73:6379@16379 master - 0 1643164181665 3 connected 10923-16383
dc22da80db3ed3e4f956a53dbe3d527d72c56e87 10.244.4.71:6379@16379 master - 0 1643164181000 1 connected 0-5460
6a8fbdafa9f4fb0c5f3fa1c0bb943a2b2dc72f5d 10.244.4.77:6379@16379 master - 0 1643164180000 7 connected 5461-10922
c0ffb0eb52b8973a9f321cb6c5559a1b45ed304e 10.244.3.32:6379@16379 myself,slave 6a8fbdafa9f4fb0c5f3fa1c0bb943a2b2dc72f5d 0 1643164181000 7 connected
d197cc2d30c43780a8854bbd75c200c00ea5b417 10.244.4.74:6379@16379 slave d4c101ecd86542797df077d945f0329e55cfcd95 0 1643164180000 3 connected
85d745b2ff1f791fd5a81b1ba7710a1087ce844f 10.244.4.75:6379@16379 slave dc22da80db3ed3e4f956a53dbe3d527d72c56e87 0 1643164180000 1 connected

항목 설명

  1. node-id : 노드를 유일하게 구분할 수 있는 ID이다. 40개 문자로 구성되면 변경되지 않는다.
  2. ip:port : 노드의 주소로 IP와 Port이다. 4.0 부터 @cluster_bus-port 가 추가되었다. 예) 127.0.0.1:7000@17000
  3. flags : master, slave, fail?, fail, handshake, noaddr, noflags가 있고, 명령을 실행한 노드에 myself 라고 표시된다.
  4. master : 슬레이브일 때 마스터 노드 ID가 표시된다.   마스터일 때는 "-"이 표시된다.
  5. ping-sent : myself가 다른 노드에 ping을 보낸 시각(Unix timestamp milliseconds)이다.   Ping-sent 시각은 Pong이 오면 지워진다.   그러므로 이 시각은 아직 Pong 오지 않았을 아주 짧은 시간만 볼 수 있다.   따라서 대부분의 경우 0으로 나온다.
  6. pong-recv : Pong을 받은 마지막 시각(Unix timestamp milliseconds)이다.
  7. config-epoch : The configuration epoch (or version) of the current node (or of the current master if the node is a slave).   Each time there is a failover, a new, unique, monotonically increasing configuration epoch is created.   If multiple nodes claim to serve the same hash slots, the one with higher configuration epoch wins.
  8. link-state : 클러스터 버스로 연결된 상태를 나타낸다.   connected 또는 disconnected 이다.
  9. slot : 마지막 항목은 할당된 슬롯 정보이다.   슬롯이 할당된 마스터 노드에 범위로 표시된다.   슬레이브나 슬롯이 할당되지 않은 마스터는 표시되지 않는다.

cluster info

 k exec -it redis-cluster-1 -- redis-cli cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:7
cluster_my_epoch:7
cluster_stats_messages_ping_sent:163087
cluster_stats_messages_pong_sent:164271
cluster_stats_messages_sent:327358
cluster_stats_messages_ping_received:164271
cluster_stats_messages_pong_received:163087
cluster_stats_messages_received:327358

항목 설명

  • cluster_state: 클러스터 상태를 나타낸다.   ok는 명령을 처리할 수 있는 상태이다.   fail은 명령을 처리할 수 없는 상태이다.   일반적으로 슬롯이 할당된 마스터 서버가 다운되었거나, 모든 슬롯이 할당되지 않으면 fail이다.   모든 슬롯이 할당되지 않아도 ok일 경우가 있는데, 이것은 cluster-require-full-coverage 파라미터에 영향을 받는다.
  • cluster_slots_assigned: 레디스 서버에 할당된 슬롯의 개수이다. 레디스 클러스터는 16384개의 슬롯이 있다.   assigned = ok + pfile + fail.
  • cluster_slots_ok: 할당된 슬롯의 개수이다. pfail이나 fail이 아닌 슬롯의 개수이다.
  • cluster_slots_pfail: 일시적으로 접속할 수 없는 노드에 할당된 슬롯 수이다.   Pfile은 Possible file의 줄임말이다.   회복되면 slots_ok가 되고, 다운되면 slots_fail이 된다.
  • cluster_slots_fail: 다운된 서버에 할당된 슬롯 수이다.
  • cluster_known_nodes: 슬레이브를 포함해서 클러스터에 연결된 모든 노드 수이다. 명령 관점에서 보면 Cluster meet 연결된 노드 수이다.
  • cluster_size: 슬롯이 할당된 마스터 서버 수이다. 마스터라도 슬롯이 할당되지 않았으면 여기에 포함되지 않는다.
  • cluster_current_epoch: The local Current Epoch variable.   This is used in order to create unique increasing version numbers during fail overs.
  • cluster_my_epoch: The Config Epoch of the node we are talking with.   This is the current configuration version assigned to this node.
  • cluster_stats_messages_sent: Number of messages sent via the cluster node-to-node binary bus.
  • cluster_stats_messages_received: Number of messages received via the cluster node-to-node binary bus.

info persistence

 k exec -it redis-cluster-1 -- redis-cli info persistence
# Persistence
loading:0
current_cow_size:0
current_cow_size_age:0
current_fork_perc:0.00
current_save_keys_processed:0
current_save_keys_total:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1643072438
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:0
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:348160
module_fork_in_progress:0
module_fork_last_cow_size:0
aof_current_size:92
aof_base_size:92
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0

항목 설명

  • aof_enabled : AOF 기능 활성화
  • aof_rewrite_in_progress : 현재 rewrite가 진행중임
  • aof_last_rewrite_time_sec : 지난 번 rewrite 하는데 걸린 시간
  • aof_current_rewrite_time_sec : 새 파일에 rewrite를 시작하고 현재까지 경과 시간
  • aof_last_bgrewrite_status : 지난 번 rewrite 상태
  • aof_current_size : 현재 AOF 파일 사이즈
  • aof_base_size : 베이스 AOF 파일 사이즈. base size와 current size를 비교해서 rewirte-percentage 값 이상이되면 자동으로 rewrite 한다.

 

 


 

Redis 저장 세션값과 의미

Key type Description
spring:session:sessions:(session id) hash 세션의 생성 시간, 마지막 세션 조회 시간, 최대 타임아웃 허용 시간과 해당 세션에 저장한 데이터를 저장
hgetall "spring:session:sessions:47caf040-8e4c-4b7e-b9c0-133a7e24c450"
 1) "lastAccessedTime"
 2) "\xac\xed\x00\x05sr\x00\x0ejava.lang.Long;\x8b\xe4\x90\xcc\x8f#\xdf\x02\x00\x01J\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\x01~\xbd\xf76\x0c"
 3) "creationTime"
 4) "\xac\xed\x00\x05sr\x00\x0ejava.lang.Long;\x8b\xe4\x90\xcc\x8f#\xdf\x02\x00\x01J\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\x01~\xbd\xf76\x0c"
 5) "sessionAttr:loginInfo"
 6) xxx
 7) "maxInactiveInterval"
 8) "\xac\xed\x00\x05sr\x00\x11java.lang.Integer\x12\xe2\xa0\xa4\xf7\x81\x878\x02\x00\x01I\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\xa8\xc0"

spring:session:sessions:expires:(session id) string identifies how long this group of keys can live and can be viewed with TTL
ttl "spring:session:sessions:expires:47caf040-8e4c-4b7e-b9c0-133a7e24c450"
(integer) 41864

spring:session:expirations:(expire time) set expire time에 삭제될 key 정보를 담고 있음.
smembers  "spring:session:expirations:1643907840000"
1) "\xac\xed\x00\x05t\x00,expires:47caf040-8e4c-4b7e-b9c0-133a7e24c450"


 


- http://redisgate.kr/redis/configuration/persistence.php

- http://redisgate.kr/redis/cluster/cluster_info.php

'빅데이터 > Redis Cluster' 카테고리의 다른 글

Redis Configuration  (0) 2022.02.08
Lettuce Configuration(RedisTemplate)  (0) 2022.02.08
Redis Cluster 장애 복구  (0) 2022.02.08
Redis Cluster Overview  (0) 2022.02.08

+ Recent posts