SlideShare a Scribd company logo
Serverless Event Streaming
With Pulsar Functions
Xiaolong Ran @wolfstudy
2019/12/08
• 开源项⽬爱好者,Go 语⾔爱好者

• TiDB -> BitMain -> StreamNative

• Apache Pulsar committer

• Go Functions

• pulsar-client-go

• pulsarctl

• …

• https://github.com/wolfstudy
Who am I
⽬录
Apache Pulsar 简介
Apache Pulsar 架构
Go Function 的设计
Go Function 的实现
Go Function 使⽤示例
Pulsar Function Runtime
Pulsar Function Worker
What is Apache Pulsar
为什么要“造轮⼦”
• 没有系统能够解决遇到的问题和规模

• 多租��� - 百万 Topics - 低延时 - 持久化 - 跨地域复制

• 已有的系统存在的问题

• 分区模型紧耦合(存储和计算)- 不是云原⽣的设计

• 存储模型过于简单,强依赖⽂件系统

• I/O 不隔离:消费者在清除 backlog 的时候会影响其它⽣产者和消费者

• 运维太痛苦 - 替换机器、服务扩容需要强制 reblance 导致服务对外不可⽤

• 可能出现消息丢失的情况
Flexible Messaging
Flexible Messaging
• One data, different ways to consume

• Queuing (aka stateless messaging)

• Shared (* RabbitMQ)

• Streaming (aka stateful messaging)

• Exclusive

• Failover (* Kafka)

• Key_Shared
Multi Tenancy
Geo-Replication
Cloud-native Architecture
计算存储分离
•独⽴扩展
• 瞬时失效恢复
• 扩容⽆需数据均衡
Pulsar View - Topic
Pulsar View - Partition
Pulsar View - Segment
Event Stream is the right foundation for your data
Apache pulsar ⽣态
When Event Streaming
Meets Serverless
Introduce Pulsar Functions
Pulsar Functions
• A serverless event streaming framework

• Lightweight computation

• Event - first, Stream - first

• Multi languages

• Multi runtimes

• SDK - less && SDK
Pulsar Functions
Pulsar Functions
Pulsar Functions
Pulsar Functions
反射 Plugin
Pulsar Functions
反射
Plugin
• Go 是⼀⻔静态类型的语⾔

• 反射⽀持的相对较弱
• 注⼊⾮���模块,会带来⼀定安全隐患

• 如果模块出现问题,会导致服务奔溃

• 给版本管理带来了困难

• 社区不成熟
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)
Go functions User Rule
Start() 函数的⼊参必须是函数类型
⽤户函数的输⼊参数可以是 0-2 个
如果有两个参数,第⼀个必须是 context.Context
如果只有⼀个输⼊参数,必须是 context.Context
⽤户函数的输出参数可以是 0-2 个
如果返回两个参数,第⼆个参数必须是 error
如果只返回⼀个参数,必须是 error
Go functions Context
Go functions - Use Case
Go functions - Use Case
Pulsar Functions - CLI
Go functions - Close channel
没有简单易⾏的⽅法去检查管道是否没有通过改变它的状态来
关闭。
关闭⼀个已经关闭的管道会触发 panic,所以,关闭者不知道
管道是否关闭仍去关闭它,这是⼀个危险的⾏为。
发送数据到⼀个关闭的管道会触发 panic, 所以,发送者不知
道管道是否关闭仍去发送消息给它,这是⼀个危险的⾏为。
原则:要在 producer 端关闭 channel
Pulsar functions 使⽤场景
ETL
Data Enrichment
Data Filtering
Dynamic Routing
Alerts and Threholds
Flexible Runtime
Colocate with Broker - Thread & Process
Managed Function Workers - Thread & Process
External Schedulers - Container
Kubernetes
Colocate with Brokers
Manager Function Workers
External Schedulers - Kubernetes
Auto load balancing
Pulsar Functions use Pulsar’s auto-balancing
mechanism on consumer
Shared Subscription
Failover Subscription
Key-Shared Subscription (feature)
Pulsar Function worker
Pulsar Function worker
• 存放元数据信息

• 接收并存储 Function 所有的状态请求

• 为了防⽌ topic 变⼤,写⼊时会进⾏压缩

• 所有数据使⽤ FQFN 作为 key 写⼊
Pulsar Function worker
• 存放调度分配信息

• 接收并存储 leader 监听到的所有状态请求

• 使⽤垃圾收集,防⽌ topic 变⼤

• 所有 worker 会订阅 assignment topic
Pulsar Function worker
• 管理 Functions Worker 的 Membership

• 每⼀个 Functions Worker 都会订阅 Coordination Topic

• Pulsar Broker 会跟踪处于活跃状态的 consumer

• 通过查询活跃状态的 consumer,获取所有处于活跃状
态的 Functions Worker
Complex Event Processing Pipelines
Community
• Mailing lists:
dev@pulsar.apache.org
users@pulsar.apache.org
• Github:
https://github.com/apache/pulsar
https://github.com/apache/pulsar-translation
• Slack:
https://apache-pulsar.slack.com/
https://apache-pulsar.herokuapp.com/
• WeChat
Apache Pulsar Users(China)
Apache Pulsar Users(global)
Thanks

More Related Content

Serverless Event Streaming with Pulsar Functions-xiaolong