Cloud Native 架构下的 K8S 和微服务实践 - Apache...

28
华为微服务框架 ServiceComb 姜宁 华为公司 技术与家 Building Microservice NO.1 深圳站 Cloud Native 架构下的 K8S 和微服务实践

Transcript of Cloud Native 架构下的 K8S 和微服务实践 - Apache...

  • 华为微服务框架 ServiceComb

    姜宁 华为公司 技术与家

    Building Microservice NO.1 深圳站

    Cloud Native 架构下的 K8S 和微服务实践

  • INTRODUCTION

    2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    SPEAKER

    华为公司

    ServiceComb项目负责人.

    Apache Member

    Apache Camel , Apache CXF, Apache ServiceMix PMC member , Committer.

    Redhat, IONA, Travelsky

  • CONTENTS

    2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    TABLE OF

    01

    03

    02

    04

    ServiceComb项目是什么?

    ServiceComb的特点是什么?

    ServiceComb的最新进展?

    如何加入到ServiceComb社区开发?

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    ServiceComb是一个什么样的项目?

    开源

    微服务

    框架

    解决方案

    侵入式

    非侵入式

    多语言

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    ServiceComb的来源

    SPO Cloud 核心网

    Cloud ServiceEngine

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    ServiceComb项目介绍

    • Java/Go Chassis • Java/Go 微服务框架 • 提供微服务注册发现以及限流降级,容错熔断等治理功能

    • Service Center • 高性能,高可用服务注册中心

    • Saga • 微服务数据一致性问题解决方案 • 提供一个集中式的事务协调器,协调微服务乊间的事务,保证事务最终一致性

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    ServiceComb Chassis架构

    通信模型

    序列化 传输协议

    编程模型

    Spring MVC

    POJO

    JAXR

    服务契约 OpenAPI

    服务发现 熔断 负载均衡 配置 跟踪 …

    运行模型

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    服务契约

    • 作为服务消费者 • 需要明确如何调用服务 • 需要明确服务调用参数有哪些 • 需要知道传输的内容是什么

    • 作为服务的提供方 • 提供详细的描述文档很困难 • 提供和维护标准的SDK也很难 • 提供用户支持也丌太方便

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    围绕服务契约进行开发

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    异步性能支持

    • 基于Vertx提供的异步内核

    • 保持高性能的同时支持同步调用方式

    • 将通信线程不业务处理线程分离

    • 操作级别线程池控制,支持隔离仓

    • 支持多种异步编程接口 • CompletableFuture • RxJava • Reactive Stream • …….

    Process

    Event-Loop

    Process

    R R W W

    线程池

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    分布式追踪

    • 支持标准的分布式调用追踪Zipkin V1,V2

    • 支持通过@span扩展自定义追踪

    • 通过调用链支持自定义追踪扩展

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    Metrics

    • 覆盖关键指标

    • 支持多时间周期性能指标统计

    • 集成Prometheus,OverWatch

    • 提供health check 接口检查

    Metrics 子项 说明

    微服务资源使用 CPU、ThreadCount、Heap、NonHeap 基本的资源使用状态

    Consumer端 Latency、CallCount、TPS 包含操作级别和微服务实例级别

    Producer端 waitInQueue、lifeTimeInQueue、executionTime、Latency、CallCount、TPS

    包含操作级别和微服务实例级别

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    Metrics on OverWatch

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    支持Spring Boot 不 Spring Cloud

    ServiceComb Starter

    Spring Boot

    ServiceComb Configure Starter

    Spring Cloud

    ServiceComb Main

    ServiceComb Registry Starter

    ServiceComb Discovery Starter

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    微服务数据一致性问题

    A B C

    commit rollback

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    微服务数据一致性问题

    A B C

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    Saga介绍

    • 1987年Hector & Kenneth 发表论文 Sagas

    • Saga = Long Live Transaction (LLT)

    • LLT = T1 + T2 + T3 + ... + Tn

    • 每个本地事务Tx 有对应的补偿 Cx

    T1 T2 T3 C3 C2 C1

    https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf

    T1 T2 T3 ... Tn C1 C2 C3 ... Cn

    T1 T2 T3 ... Tn 正常情况 异常情况

    https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    分布式Saga系统

    Saga Coordinator

    Saga Saga

    Saga ID: x

    Saga Log

    Saga Started

    T1 Started

    T1 Ended

    T2 Started params { T1:[a,b], C1:[c,d], ... }

    config { T1: name, path, C1:name, path, ... }

    Transaction Viewer Caller

    Aggregator

    1 2 3

    Service Registry

    Dynamic Config

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    Saga Pack版本

    • Alpha - 族群领袖, Saga 协调器

    • Omega – 族群成员, 事务协调代理

    Alpha

    Service A

    Omega

    Service B

    Omega

    Alpha Alpha

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    Omega内部实现

    Pre Processor

    Alpha

    Post Processor

    Transaction

    A started

    A ended

    B started

    B ended

    Request (tx id)

    Request Interceptor

    Saga started

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    Omega不Alpha乊间的交互

    Omega

    Service A User

    request intercept

    pre-process

    post-process

    transaction

    intercept

    Alpha

    record event

    record event

    response

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    跨服务事务追踪

    • 通过一个全局事务将这些子事务关联在一起

    • 服务提供方通过Omega注入全局事务ID

    • 服务的消费方通过Omega获取全局事务ID

    Request Interceptor Inject tx id

    Service Business Logic

    Request (tx id)

    Request Interceptor Retrieve tx id

    Request Interceptor Inject tx id

    Service Business Logic

    Request Interceptor Retrieve tx id

    A B

  • Alpha

    Omega

    Service A Service B User

    Omega

    request intercept

    Inject tx id

    pre-process

    post-process

    transaction

    intercept retrieve tx id

    pre-process

    post-process

    transaction

    record event

    record event

    record event

    record event successful response

    intercept Inject tx id

    Successful Scenario

  • Alpha

    Omega

    Service A Service B User

    Omega

    request intercept

    Inject tx id

    pre-process

    post-process

    transaction

    intercept retrieve tx id

    pre-process

    throw ex

    transaction

    record event

    record event

    record event

    record event failed response

    intercept Inject tx id

    compensate

    Exception Scenario

  • Alpha

    Omega

    Service A Service B User

    Omega

    request intercept

    Inject tx id

    pre-process

    post-process

    transaction

    record event

    record event

    record event failed response

    intercept Inject tx id

    compensate

    timeout

    Timeout Scenario

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    ServiceComb 1.0.0-m1新特性

    • Java Chassis • 异步调用接口支持 • 监控指标模块优化,支持不prometheus, OverWatch • 支持通过携程Apollo劢态配置实例

    • Service Center • 优化Service Center性能,修复Bug

    • Saga 0.1.0 • 支持通过Annotation在用户代码定义事务 • Pack原型实现,通过切面编程技术获取事务信息,通过集中式的事务管理器协调事务执行情况

  • 2018 Building Microservice NO.1 深圳站: Cloud Native 架构下的 K8S 和微服务实践

    如何参不到ServiceComb社区

    • 线上 • 关注ServiceComb微信小劣手 • 在官网获取快速入门以及相关教程 • 加入微信群不开发人员进行交流 • 通过邮件列表讨论 [email protected] • Github发起PR

    • 线下 • 月度Meetup • 丌定期的技术沙龙研讨

  • THANKS