Serverless Event Streaming with Pulsar Functions-xiaolong
- 2. • 开源项⽬爱好者,Go 语⾔爱好者
• TiDB -> BitMain -> StreamNative
• Apache Pulsar committer
• Go Functions
• pulsar-client-go
• pulsarctl
• …
• https://github.com/wolfstudy
Who am I
- 3. ⽬录
Apache Pulsar 简介
Apache Pulsar 架构
Go Function 的设计
Go Function 的实现
Go Function 使⽤示例
Pulsar Function Runtime
Pulsar Function Worker
- 5. 为什么要“造轮⼦”
• 没有系���能够解决遇到的问题和规模
• 多租户 - 百万 Topics - 低延时 - 持久化 - 跨地域复制
• 已有的系统存在的问题
• 分区模型紧耦合(存储和计算)- 不是云原⽣的设计
• 存储模型过于简单,强依赖⽂件系统
• I/O 不隔离:消费者在清除 backlog 的时候会影响其它⽣产者和消费者
• 运维太痛苦 - 替换机器、服务扩容需要强制 reblance 导致服务对外不可⽤
• 可能出现消息丢失的情况
- 7. Flexible Messaging
• One data, di��erent ways to consume
• Queuing (aka stateless messaging)
• Shared (* RabbitMQ)
• Streaming (aka stateful messaging)
• Exclusive
• Failover (* Kafka)
• Key_Shared
- 18. Pulsar Functions
• A serverless event streaming framework
• Lightweight computation
• Event - first, Stream - first
• Multi languages
• Multi runtimes
• SDK - less && SDK
- 24. Go functions User Rule
func ()
func () error
func (input) error
func () (output, error)
func (input) (output, error)
func (context.Context) error
func (context.Context, input) error
func (context.Context) (output, error)
func (context.Context, input) (output, error)
- 25. Go functions User Rule
Start() 函数的⼊参必须是函数类型
⽤户函数的输⼊参数可以是 0-2 个
如果有两个参数,第⼀个必须是 context.Context
如果只有⼀个输⼊参数,必须是 context.Context
⽤户函数的输出参数可以是 0-2 个
如果返回两个参数,第⼆个参数必须是 error
如果只返回⼀个参数,必须是 error
- 30. Go functions - Close channel
没有简单易⾏的⽅法去检查管道是否没有通过改变它的状态来
关闭。
关闭⼀个已经关闭的管道会触发 panic,所以,关闭者不知道
管道是否关闭仍去关闭它,这是⼀个危险的⾏为。
发送数据到⼀个关闭的管道会触发 panic, 所以,发送者不知
道管道是否关闭仍去发送消息给它,这是⼀个危险的⾏为。
原则:要在 producer 端关闭 channel
- 36. Auto load balancing
Pulsar Functions use Pulsar’s auto-balancing
mechanism on consumer
Shared Subscription
Failover Subscription
Key-Shared Subscription (feature)
- 40. Pulsar Function worker
• 管理 Functions Worker 的 Membership
• 每⼀个 Functions Worker 都会订阅 Coordination Topic
• Pulsar Broker 会跟踪处于活跃状态的 consumer
• 通过查询活跃状态的 consumer,获取所有处于活跃状
态的 Functions Worker