Hot Data (logs from the last few days or weeks): Stored in fast storage (like SSDs) for frequent access.
Cold Data (historical logs): Stored in object storage (like MinIO, S3) for long-term archiving and infrequent access.
Example Loki Configuration:
1 2 3 4 5 6 7 8 9 10 11
storage_config: boltdb_shipper: active_index_directory:/var/loki/index# Hot data directory shared_store:s3# Use MinIO/S3 as cold data storage cache_location:/var/loki/cache# Cache directory
aws: s3:http://minio-service.minio.svc.cluster.local:9000# Address of MinIO bucketnames:loki-logs access_key_id:minio secret_access_key:minio123
Optimization Effect:
Reduces local storage pressure by moving historical logs to object storage.
Improves query performance: prioritizes hot data queries, with slightly higher latency for cold data queries but at lower costs. ---
2. Compress Logs and Indexes
Enable Log Compression: Loki compresses logs by default using chunks, and you can adjust the chunk size and compression level to optimize storage space.
Choose Appropriate Compression Algorithm (like Snappy or GZIP):
1 2 3 4
ingester: chunk_encoding:snappy# Use Snappy to compress chunks chunk_idle_period:5m# Set the closing time for idle chunks max_chunk_age:1h# Maximum lifespan for each chunk
Adjust Chunk Size: Larger chunks can reduce the number of index entries but will increase memory usage. Tune according to log volume and access patterns.
3. Optimize Index Configuration
Boltdb-shipper: It is recommended to use Boltdb-shipper to store indexes, reducing reliance on external databases (like Cassandra).
Reduce the Number of Index Entries: Lower the index size by disabling unnecessary labels or reducing the number of labels in the Loki configuration:
Set query concurrency and rate limits to prevent the Loki cluster from crashing under high query loads:
1 2 3 4
limits_config: max_concurrent_queries:20# Maximum number of concurrent queries max_query_timeout:2m# Query timeout duration max_entries_per_query:5000# Maximum number of entries per single query
9. Use Headless Service to Improve Throughput
In the Loki cluster, use a Headless Service to avoid the load balancer becoming a bottleneck: