Zookeeper Configuration¶
Reference for zoo.cfg / zookeeper.properties parameters. See also the Apache ZooKeeper Admin Guide.
tickTime¶
tickTime is the base time unit (milliseconds) for all time-related operations inside the ensemble. It is the foundation of ZooKeeper’s timing model.
Heartbeat checks, session validation, and other scheduled tasks run in multiples of tickTime.
Treat tickTime as the cluster “heartbeat pulse”—it controls sensitivity to network latency and overall stability. Tune it for your network.
tickTime Default Value¶
tickTime Applicable Scene¶
Global (all nodes must match).
tickTime Configuration Policy¶
tickTime ≤ minimum expected session timeout / 2
tickTime ≥ maximum expected session timeout / 20
# Suggested values
# LAN: 2000–3000 ms (2–3 s)
# Cross-region / high-latency: 4000–5000 ms (4–5 s)
Warning
- Increase tickTime to tolerate network jitter on high-latency or unstable links.
- Too small (<1000 ms) causes false session timeouts and extra network load.
- All nodes must use the same
tickTimeafter any change.
initLimit¶
initLimit caps how long a new or restarting follower may take to sync with the leader, expressed in tickTime units.
Think of it as the “join gate”—too low blocks joins; too high hides slow sync. Tune using zkServer.sh status and join/recovery metrics.
initLimit Default Value¶
initLimit Applicable Scene¶
- New follower joining the ensemble
- Crashed follower reconnecting
- Post-election leader–follower initialization
initLimit Configuration Policy¶
| Scenario | Direction | Suggested | Rationale |
|---|---|---|---|
| Large dataset (>1 GB) | Increase | initLimit=15 | Longer initial sync |
| Cross-region ensemble | Increase | initLimit=12 | Higher RTT |
| Local SSD cluster | Decrease | initLimit=5 | Fast sync |
| Frequent restarts | Increase | initLimit=8 | Recovery buffer |
initLimit Possible Fault¶
| Symptom | Root cause | Fix |
|---|---|---|
| New node fails to join repeatedly | initLimit too low | Increase initLimit |
| Recovery time grows over time | Data growth, params unchanged | Scale initLimit with data size |
| Remote node cannot join | RTT exceeds limit | Increase initLimit and/or improve network |
| Frequent join timeouts | tickTime too small | Increase both tickTime and initLimit |
syncLimit¶
syncLimit limits how long the leader waits for a follower to respond to a request (heartbeat, log push, write ack), in tickTime units.
syncLimit Default Value¶
syncLimit Applicable Scene¶
- Leader → follower heartbeats
- Transaction log (zxid) replication
- Write quorum acknowledgements
syncLimit Configuration Policy¶
| Scenario | Direction | Suggested | Rationale |
|---|---|---|---|
| Cross-region (>100 ms RTT) | Increase | syncLimit=8 | Absorb latency |
| Local high-performance cluster | Decrease | syncLimit=2 | Faster failure detection |
| Heavily loaded followers | Increase | syncLimit=6 | Processing headroom |
| SSD-backed cluster | Decrease | syncLimit=3 | Fast I/O |
# Constraints
syncLimit < initLimit # often syncLimit <= initLimit/2
# Rule of thumb
syncLimit * tickTime > average_RTT × 3
syncLimit Possible Fault¶
| Symptom | Root cause | Fix |
|---|---|---|
| Followers drop frequently | syncLimit too low | Increase syncLimit |
| Leader marks healthy follower dead | Transient jitter | Slightly increase syncLimit |
| Cluster feels sluggish | syncLimit too high | Decrease to expose bottlenecks |
| Cross-DC sync timeouts | RTT exceeds limit | Increase syncLimit or optimize network |
Warning
syncLimit is the cluster “heartbeat monitor”: 1. Too low — false positives, unnecessary reconfiguration. 2. Too high — slow failure detection, lower availability. Use zkServer.sh status latency min/avg/max to tune over time.
dataDir¶
dataDir stores in-memory database snapshots and ensemble metadata. Required for persistence.
It affects durability, recovery, and I/O. Manage it together with autopurge.* and metrics.
dataDir Default Value¶
dataDir Contents¶
| Data type | File pattern | Importance | Description |
|---|---|---|---|
| Memory DB snapshot | snapshot.* | ★★★ | Point-in-time full state |
| Transaction log | log.* | ★★★ | Ordered change sequence |
| Server id | myid | ★★ | Node id (1–255) |
| Version dir | version-2/ | ★ | Data format version |
| Temp files | *.tmp | - | In-flight operations |
When
dataLogDiris set, transaction logs go there; snapshots remain underdataDir.
dataDir Layout¶
/var/lib/zookeeper/data/
├── version-2/
│ ├── log.100000001
│ ├── snapshot.100000000
├── myid
└── acceptedEpoch
dataDir Configuration Policy¶
| Data size | Capacity plan | Notes |
|---|---|---|
| < 10 GB | 3× data size | Logs + snapshots + headroom |
| 10–100 GB | 2.5× data size | Compression efficiency |
| > 100 GB | 2× data size | Requires autopurge |
dataDir Troubleshooting¶
| Symptom | Fix |
|---|---|
| Disk full | Increase autopurge.purgeInterval frequency |
| Invalid dataDir on start | Check permissions and SELinux |
| Corrupt snapshot | Recover from latest log (SnapshotFormatter) |
| Inconsistent nodes | Compare zxid; resync snapshots |
dataDir Recovery Tools¶
java -cp zookeeper.jar:lib/* org.apache.zookeeper.server.SnapshotFormatter snapshot.100000000
java -cp zookeeper.jar:lib/* org.apache.zookeeper.server.LogFormatter log.100000001
dataDir Backup Example¶
zk_backup_dir="/backup/$(date +%Y%m%d)"
mkdir -p $zk_backup_dir
cp $dataDir/version-2/snapshot.* $zk_backup_dir
cp $dataDir/version-2/log.* $zk_backup_dir
Related Optimizations¶
-
Separate transaction logs
-
Filesystem
-
JVM
dataLogDir¶
Optional directory dedicated to transaction logs. Pair with dataDir for high write throughput.
dataLogDir Default Value¶
None (logs use dataDir when unset).
dataLogDir vs dataDir¶
| Aspect | dataLogDir | dataDir |
|---|---|---|
| Stores | Transaction logs (log.*) | Snapshots, myid |
| I/O pattern | Sequential writes | Mixed read/write |
| Performance | High write throughput | Moderate |
| Required | No | Yes |
| Loss impact | High (consistency risk) | Recoverable from logs |
dataLogDir Performance¶
- Why separate: avoids log sequential writes competing with snapshot random I/O.
-
Hardware: put logs on fast SSD; snapshots can use HDD.
-
Recovery: log corruption is severe; snapshot corruption can often be rebuilt from logs.
dataLogDir Layout¶
- Naming:
log.<zxid> - Default segment size: 64 MB (
preAllocSize)
dataLogDir Configuration Policy¶
| Metric | Recommendation | Notes |
|---|---|---|
| Disk type | NVMe or fast SAS SSD | Sequential write |
| IOPS | >5000 (4 KB blocks) | Write-heavy load |
| Capacity | daily growth × retention × 2 | Uncompressed logs |
| Filesystem | XFS or ext4 (noatime) | Disable atime |
dataLogDir Maintenance¶
java -cp zookeeper.jar:lib/* \
org.apache.zookeeper.server.LogFormatter log.100000001 | tail -100
kill -SIGUSR1 <zk_pid>
dataLogDir Faults¶
| Symptom | Fix |
|---|---|
| Log disk full | Increase purge frequency |
| SSD wear | Enable compression (e.g. ZFS) |
| Permission errors | setfacl -Rm u:zookeeper:rwx /data_logs |
| Corrupt log segment | zkCleanup.sh |
dataLogDir Recovery Flow¶
graph TB
A[Detect log corruption] --> B[Stop ensemble]
B --> C[Backup existing files]
C --> D[SnapshotFormatter analysis]
D --> E[Find last valid zxid]
E --> F[Remove invalid segments]
F --> G[Restart ensemble] dataLogDir Summary¶
- Core to write performance
- Physically separate from
dataDirin production - Use SSD for logs
- Alert above ~80% disk usage
- Periodically validate logs with LogFormatter
Tip
A dedicated dataLogDir on SSD often improves write throughput 3–5× and lowers client latency.
clientPort¶
Port for client connections.
clientPort Default Value¶
maxClientCnxns¶
Maximum concurrent client connections per IP (default often 60). Increase if you expect more clients from one host.
maxClientCnxns Default Value¶
autopurge.snapRetainCount¶
Number of snapshots to retain under dataDir. See maintenance.
autopurge.snapRetainCount Default Value¶
autopurge.purgeInterval¶
Purge interval in hours. Set 0 to disable automatic purge.
autopurge.purgeInterval Default Value¶
metricsProvider¶
Prometheus metrics exporter. See prometheus.io.
metricsProvider Default Value¶
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
Zookeeper Time Parameters¶
Time Parameter Relationships¶
graph LR
A[tickTime] --> B[Heartbeat interval]
A --> C[initLimit timeout]
A --> D[syncLimit timeout]
A --> E[Session timeout]
B -->|every tickTime ms| F[Inter-server heartbeat]
C -->|initLimit*tickTime| G[New node join window]
D -->|syncLimit*tickTime| H[Leader-follower sync window]
E -->|2~20*tickTime| I[Client session lifetime] Timeout Calculations¶
| Parameter | Formula | Meaning |
|---|---|---|
| tickTime | 1 × tickTime | Heartbeat tick |
| initLimit | initLimit × tickTime | Join/recovery window |
| syncLimit | syncLimit × tickTime | Request/ack window |
| sessionTimeout | minSessionTimeout ~ maxSessionTimeout | Client session (default 2–20× tickTime) |
Time-Related Errors¶
- Frequent session expiry: tickTime too low + jitter → increase tickTime and review session bounds.
-
Join failures: ensure
initLimit × tickTimeexceeds actual sync time. -
Sync delay warnings: ensure
syncLimit × tickTimecovers cross-DC RTT.
Zookeeper Cluster Communication¶
Node Joining the Ensemble¶
sequenceDiagram
participant NewFollower
participant Leader
Note over NewFollower: 1. Connect request
NewFollower->>Leader: CONNECT_REQUEST
Note over Leader: 2. Connect ack
Leader-->>NewFollower: CONNECT_ACK
Note over NewFollower: 3. Initial sync request
NewFollower->>Leader: SYNC_REQUEST
Note over Leader: 4. Snapshot stream
Leader-->>NewFollower: SNAPSHOT_STREAM
Note over NewFollower: 5. Validation
NewFollower->>Leader: VALIDATION_REPORT
Note over Leader: 6. Sync complete
Leader-->>NewFollower: SYNC_COMPLETE
Note right of Leader: Deadline: initLimit*tickTime
alt Within deadline
Leader-->>NewFollower: WELCOME_TO_CLUSTER
else Timeout
Leader-->>NewFollower: CONNECTION_DROP
end Cluster Heartbeat¶
sequenceDiagram
participant Leader
participant Follower
Note over Leader: 1. Heartbeat / request
Leader->>Follower: REQUEST(id=123)
Note over Leader: Timer: syncLimit*tickTime
rect rgb(255,240,240)
Note over Follower: Processing...
Follower-->>Leader: ACK(id=123)
end
alt ACK within syncLimit*tickTime
Leader-->Leader: Mark follower alive
else Timeout
Leader-->Leader: Mark follower lost
Leader-->Leader: Possible reconfig
end Zookeeper Data Write Path¶
Write Path Overview¶
graph TD
A[Client write] --> B[Leader]
B --> C[Write txn log]
C --> D[Update in-memory DB]
D --> E[Broadcast to followers]
E --> F[Followers write local log]
F --> G[Periodic snapshot]
G --> H[Purge old logs] Transaction Log Path¶
graph LR
A[Write request] --> B[Leader]
B --> C[Txn log dataLogDir]
C --> D[Update memory state]
D --> E[Snapshot dataDir]
E --> F[Reply to client]