pulsar分层存储配置

文章目录

开启s3Driver

开启冷热存储需要先看一下是否开启了相应的driver。

bash 复制代码
#查看配置文件
cat broker.conf | grep -i offload
#开启
bin/pulsar-admin namespaces set-offload-policies public/default \
  -d aws-s3 \
  -b pulsar-test-fast \
  -e http://xxxx
#查看
bin/pulsar-admin namespaces get-offload-policies public/default

分层测试相关配置

未消费消息TTL

POST /admin/v2/namespaces/{tenant}/{namespace}/messageTTL

https://pulsar.apache.org/admin-rest-api/?version=4.0.1\&apiVersion=v2#operation/Namespaces_setNamespaceMessageTTL

边界值说明

复制代码
0 意味关闭 TTL;>0 则按秒生效;

已消费数据保留策略

pulsar官方文档说明了这两个配置的各种值的含义。

https://pulsar.apache.org/docs/next/cookbooks-retention-expiry/

结论:默认配置下,retentionSizeInMBretentionTimeInMinutes配置生效。

POST /admin/v2/namespaces/{tenant}/{namespace}/retention

https://pulsar.apache.org/admin-rest-api/?version=4.0.1\&apiVersion=v2#operation/Namespaces_setRetention

边界值说明

复制代码
{
  "retentionTimeInMinutes": 0,//-1:无限保留,0:不保留,>0 保留指定时间
  "retentionSizeInMB": 0//如果用户已消费数据保留大于0,则固定传-1,表示忽略大小纬度,如果用户已消费数据保留大于0,则固定传0,表示消费完即删除,不保留
}

关闭冷热分层

结论:

1,关闭冷热分层后已消费消息被删除,offloaded为false,生效。

2,开启冷热分层后已消费消息被转移,offloaded为true,生效。

/admin/v2/namespaces/{tenant}/{namespace}/offloadThresholdInSeconds

https://pulsar.apache.org/admin-rest-api/?version=4.0.1\&apiVersion=v2#operation/Namespaces_setOffloadThresholdInSeconds

边界值说明

复制代码
单位秒
-1:关闭冷热数据分层,0:立刻 offload

热数据保留策略

结论:

1,=0,offloaded之后就会删除,无法查到ledger。(即使《已消费保留策略》设置成永久保留,也会立马删除)

2,>0时,offloaded之后,经过设置的规定时间,就会删除。

PUT /admin/v2/namespaces/{tenant}/{namespace}/offloadDeletionLagMs

https://pulsar.apache.org/admin-rest-api/?version=4.0.1\&apiVersion=v2#operation/Namespaces_setOffloadDeletionLag

复制代码
>0 延迟指定毫秒后删除,0 立即删本地段,-1 永不删除本地段

pulsar重启对bookkeeper的影响

复制代码
./bin/pulsar-admin \
    --admin-url http://xxxxxxxxx:8080 \
    namespaces get-persistence public/default
    
bin/pulsar-admin namespaces set-persistence public/default \
  --bookkeeper-ensemble 3 \
  --bookkeeper-write-quorum 3 \
  --bookkeeper-ack-quorum 3 \
  --size 10M

bin/pulsar-perf produce persistent://public/default/219 --batch-max-messages 10 --max-outstanding 1000 --rate 1000000 --test-duration 900 --size 1024 > testP1.log &

测试常用命令

bin命令

bash 复制代码
#已消费消息保留策略
bin/pulsar-admin topics set-retention   persistent://public/default/my-topic1   --size 0 --time 0
bin/pulsar-admin namespaces get-retention public/default
bin/pulsar-admin topics get-retention persistent://public/default/my-topic3
#查看topic存储大小
bin/pulsar-admin topics stats persistent://public/default/my-topic2 | grep storageSize

#冷热分层配置
bin/pulsar-admin namespaces get-offload-threshold public/default
bin/pulsar-admin namespaces -offload-policies public/default
#冷热分层
 bin/pulsar-admin topics stats persistent://public/default/offload-test | grep -E "storageSize|offloaded"
 bin/pulsar-admin topics stats persistent://public/default/cold-hot-test | grep -E "storageSize|offloadedStorageSize|offloaded"
# 查看当前集群配置offloader情况
bin/pulsar-admin namespaces get-offload-policies public/default
#查看 Pulsar 主题的「内部存储细节」,并筛选出与「Ledger(账本)」相关的关键信息(前后显示 10 行上下文)
bin/pulsar-admin topics stats-internal persistent://public/default/final-test | grep -A 10 ledgers

#延迟配置
bin/pulsar-admin namespaces set-offload-deletion-lag public/default --lag 0
bin/pulsar-admin namespaces get-offload-deletion-lag public/default

#手动关闭
bin/pulsar-admin topics unload persistent://public/default/offload-test

#查看ledger详情
bin/pulsar-admin topics stats-internal persistent://public/default/final-test

#unload
bin/pulsar-admin topics unload persistent://public/default/offload-test

测试数据命令

bash 复制代码
#创建topic
bin/pulsar-admin topics create persistent://public/default/my-topic
#生产者
bin/pulsar-perf produce persistent://public/default/224 --batch-max-messages 10 --max-outstanding 1000 --rate 1000000 --test-duration 900 --size 1024 > testP1.log &
#消费者
bin/pulsar-perf consume persistent://public/default/224 -n 8 -q 10000 --subscriptions perf-consume-sub --test-duration 300 -r 0 --subscription-type Shared > consumeP1.log &

------------------------------配置(通过接口的形式)--------------------------------
#已消费消息保留策略
curl -X POST http://xxxxxxxxx:8080/admin/v2/namespaces/public/default/retention \
     -H "Content-Type: application/json" \
     -d '{
           "retentionTimeInMinutes": 1,
           "retentionSizeInMB": -1
         }'
#ttl
curl -X POST http://xxxxxxxxx:8080/admin/v2/namespaces/public/default/messageTTL      -H "Content-Type: application/json"      -d '0'
#查看ledger,如果是500,则不存在
curl -v "http://pulsartest5.cloud.bjpdc.qihoo.net:8001/api/v1/ledger/metadata/?ledger_id=1339752"
bash 复制代码
#发送少量的消息
for i in {1..10}; do
  echo "bin/pulsar-client produce persistent://public/default/243 --messages \"hello-243-message-$i\" -n 1"
  bin/pulsar-client produce persistent://public/default/243 \
      --messages "hello-243-message-$i $(date +%F_%T.%3N)" -n 1
done
相关推荐
莫比乌斯环5 小时前
【Android技能点】深入解析 Android 中 Handler、Looper 和 Message 的关系及全局监听方案
android·消息队列
利刃大大9 小时前
【RabbitMQ】详细使用:工作队列 && 发布/订阅模式 && 路由模式 && 通配符模式 && RPC模式 && 发布确认机制
分布式·rpc·消息队列·rabbitmq
利刃大大1 天前
【RabbitMQ】Simple模式 && 工作队列 && 发布/订阅模式 && 路由模式 && 通配符模式 && RPC模式 && 发布确认机制
rpc·消息队列·rabbitmq·队列
闲人编程2 天前
消息通知系统实现:构建高可用、可扩展的企业级通知服务
java·服务器·网络·python·消息队列·异步处理·分发器
进阶的小名2 天前
[超轻量级消息队列(MQ)] Redis 不只是缓存:我用 Redis Stream 实现了一个 MQ(自定义注解方式)
数据库·spring boot·redis·缓存·消息队列·个人开发
利刃大大3 天前
【RabbitMQ】安装详解 && 什么是MQ && RabbitMQ介绍
分布式·中间件·消息队列·rabbitmq·mq
indexsunny3 天前
互联网大厂Java求职面试实战:Spring Boot微服务与Redis缓存场景解析
java·spring boot·redis·缓存·微服务·消息队列·电商
技术小泽5 天前
MQTT从入门到实战
java·后端·kafka·消息队列·嵌入式
遇见火星6 天前
RabbitMQ 高可用:HAProxy 负载均衡实战指南
分布式·消息队列·rabbitmq·负载均衡·haproxy
闲人编程6 天前
电商平台用户系统API设计
数据库·后端·消息队列·fastapi·监控·容器化·codecapsule