Go构建日请求千亿微服务最佳实践的副本

Similar documents
Microsoft Word doc

Guide to Install SATA Hard Disks

VHDL(Statements) (Sequential Statement) (Concurrent Statement) VHDL (Architecture)VHDL (PROCESS)(Sub-program) 2

穨control.PDF

Panaboard Overlayer help

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2

CC213

C/C++ - 字符输入输出和字符确认

IP505SM_manual_cn.doc








1

untitled

月光迴旋曲

C/C++ - 文件IO

SA-DK2-U3Rユーザーズマニュアル


3.1 num = 3 ch = 'C' 2

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

第5章修改稿

A Preliminary Implementation of Linux Kernel Virus and Process Hiding

经 济 高 速 增 长 和 其 后 又 比 其 他 发 达 资 本 主 义 国 家 更 为 顺 利 地 克 服 了 石 油 危 机 的 冲 击, 使 日 本 的 市 场 经 济 体 制 在 7 0 ~ 8 0 年 代 赢 得 了 国 际 社 会 的 广 泛 赞 誉 ( 其 间 虽 有 欧 美 国 家

2015 TB-1-06.indd

C/C++ - 函数

Microsoft Word - SupplyIT manual 3_cn_david.doc

LK110_ck

Process Data flow Data store External entity 6-10 Context diagram Level 0 diagram Level 1 diagram Level 2 diagram

提纲 1 2 OS Examples for 3

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING

AL-MX200 Series

AL-M200 Series

f2.eps

ebook14-4

第一章

关于规范区委、区委办公室发文

Microsoft Word - ??山

Microsoft Word - 助理人員教育訓練-會計室.docx

操作指导手册

Spyder Anaconda Spyder Python Spyder Python Spyder Spyder Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Sp

User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2

KDC-U5049 KDC-U4049 Made for ipod, and Made for iphone mean that an electronic accessory has been designed to connect specifically to ipod, or iphone,

Microsoft PowerPoint - OPVB1基本VB.ppt

Model P53 pH-ORP Analyzer CH.doc

CAUTION RISK OF ELECTRIC SHOCK DO NOT OPEN 2

ARM JTAG实时仿真器安装使用指南

ebook 132-6

操作手冊

行业

(Microsoft Word - 013_\261i\245\303\274w_\251w\275Z_p _ _R2_ )

科学计算的语言-FORTRAN95


今天 年春季号 总 92 期

*

( ) / / / / / / /

(Microsoft Word - 8\244T\244\362\277\337\272]\244W\265L\246W.doc)

Microsoft Word - 專家本色 doc


但, 你 应 该 听 过 我 们 走 在 大 路 上 这 首 歌, 或 许 还 知 道 革 命 人 永 远 是 年 轻 那 支 歌 ; 并 且, 几 乎 可 以 肯 定, 你 在 戴 红 领 巾 的 那 阵, 必 然 唱 过 牛 儿 还 在 山 坡 吃 草, 放 牛 的 却 不 知 道 哪 儿 去

2 临 终 助 念 答 问 序 临 终 关 怀, 由 佛 门 净 宗 古 来 祖 师 大 德 提 倡 助 念 往 生, 现 今 已 渐 为 社 会 大 众 所 重 视, 在 台 湾, 台 大 长 庚 等 各 大 医 院, 也 都 设 有 助 念 室 ; 大 陆 上 许 多 道 场, 也 有 专 为

校园之星

Microsoft Word - 澎湖田調報告-宏達組9804.doc

<4D F736F F F696E74202D FA8BEA861B8EAB7BDBEE3A658BB50C0B3A5CE28B773A6CBA5AB29>

之 原 則 及 國 防 部 訂 頒 國 軍 列 管 國 有 不 動 產 提 供 非 軍 方 單 位 使 用 處 理 原 則 規 定 不 符, 仍 應 以 出 租 方 式 辦 理 惟 可 就 偏 遠 地 區 提 供 官 兵 金 融 水 電 服 務 使 用 部 分, 研 議 降 低 租 金 標 準, 報

chineseall

釋禪波羅蜜次第法門

证券代码: 证券简称:锦江股份 公告编号:【】

1700 装 卸 搬 运 7645 装 卸 搬 运 服 务 2100 建 筑 7410 工 程 服 务 11% 装 卸 搬 运 服 务, 是 指 使 用 装 卸 搬 运 工 具 或 者 人 力 畜 力 将 货 物 在 运 输 工 具 之 间 装 卸 现 场 之 间 或 者 运 输 工 具 与 装 卸

前 言 教 育 无 小 事, 它 成 就 着 学 生 的 未 来 作 为 教 师, 他 们 无 时 无 刻 不 在 关 注 着 学 生 的 成 长 学 生 的 未 来 学 生 就 像 一 朵 含 苞 待 放 的 花 朵, 需 要 老 师 们 的 细 心 呵 护, 给 学 生 需 要 的 东 西, 而

《盗墓笔记》 南派三叔/著

平 凡 足 迹 李 本 川 作 者 为 中 国 科 学 院 海 洋 研 究 所 研 究 员,1935 年 生, 山 东 荣 成 人 我 今 年 63 岁 了 大 前 年 丈 夫 和 儿 子 在 一 个 月 内 先 后 离 开 了 人 世, 女 儿 又 已 出 嫁, 现 在 是 孑 然 一 身 我 是

<CFFBB7D1D5DFD0D0CEAAD1A72E6D7073>

独立学院建设与发展


TX-NR3030_BAS_Cs_ indd

2 2 3 DLight CPU I/O DLight Oracle Solaris (DTrace) C/C++ Solaris DLight DTrace DLight DLight DLight C C++ Fortran CPU I/O DLight AM

PIC_SERVER (11) SMTP ( ) ( ) PIC_SERVER (10) SMTP PIC_SERVER (event driven) PIC_SERVER SMTP 1. E-

RunPC2_.doc

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

2 控 制 面 板 控 制 面 板 控 制 面 板 显 示 打 印 机 的 工 作 状 态, 并 控 制 打 印 机 的 基 本 操 作 图 2 ZT230 控 制 面 板 图 3 ZT220 控 制 面 板

Open topic Bellman-Ford算法与负环

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco

2_dvdr3380_97_CT_21221b.indd

1 1

行业

案例正文:(幼圆、小三、加粗)(全文段前与段后0

概述

行业


目 次 夢 醒 時 分 212 陳 俊 宇 38 快 樂 的 定 義 212 羅 柏 凱 38 鳳 梨 122 賴 會 欣 39 一 件 難 忘 的 事 211 蔡 凱 翔 39 一 趟 豐 富 的 旅 程 213 蕭 晏 琳 40 在 心 中 發 現 美 203 陳 宏 睿 40 三 一 一 日

WWW PHP

RS-232C [11-13] 1 1 (PLC) (HMI) Visual Basic (PLC) 402

C语言的应用.PDF


coverage2.ppt

Transcription:

Go 构建 请求千亿级微服务实践 项超

100+ 700 万 3000 亿

Goroutine & Channel

Goroutine Channel Goroutine func gen() chan int { out := make(chan int) go func(){ for i:=0; i<100; i++ { out <- i func seq(input chan int) { for num := range input { fmt.println(num) } } } }() return out func main(){ seq(gen()) } }

Goroutine Goroutine Channel Goroutine Goroutine func main(){ in := gen() go seq(in) go sep(in) go seq(in) }

Goroutine Goroutine Channel Goroutine Goroutine func main(){ out := make(chan int) func spout(out chan int) { for i:=0; i<100; i++ { out<-i } go spout(out) go spout(out) go spout(out) seq(out) } }

Problem: To print in ascending order all primes less than 10000. Use an array of processes, SIEVE, in which each process inputs a prime from its predecessor and prints it. The process then inputs an ascending stream of numbers from its predecessor and passes them on to its successor, suppressing any that are multiples of the original prime. Communicating Sequential Processes

10 9 8 7 6 5 4 3 2 2 9 7 5 3 3 7 5 5 7 7

func main() { origin, wait := make(chan int), make(chan struct{}) Processor(origin, wait) for num := 2; num < 10000; num++ { origin <- num } close(origin) <-wait }

func Processor(seq chan int, wait chan struct{}) { go func() { prime, ok := <-seq if!ok { close(wait) return } fmt.println(prime) out := make(chan int) Processor(out, wait) for num := range seq { if num%prime!= 0 { out <- num } } close(out) }() }

Wait Cancel

Server A Server B Requests GW Server C Server D Server E

Wait Processor Processor Wait Processor

Wait wg := sync.waitgroup{} wg.add(3) go func() { defer wg.done() // do... go func() { defer wg.done() // do... }() }() go func() { defer wg.done() // do... }() wg.wait()

Cancel Processor Cancel Processor Processor

Cancel type SIG struct{} exit := make(chan SIG) func Processor(exit chan SIG) { for { select { go Processor(exit) go Processor(exit) go Processor(exit) case <-exit: return default: // do... // Cancel after 1s time.sleep(time.second) close(exit) } } }

User Request User Request User Request User Request User Request User Request User Request User Request Dependency A Dependency B Dependency C Dependency D Dependency E Dependency F Dependency G Dependency H Dependency I Dependency J Dependency K Dependency L Dependency M Dependency N Dependency O Dependency P

Reset ReadTimeout Start Connect Write Read End Reset WriteTimeout 写超时读超时

Real Process Done Event Request Concurrent Ctrl Yes Wait Response No Timeout Clock Timeout Event

Go1.7 context

import ( ) "context" func Handler(r *Request) { timeout := r.value("timeout") ctx, cancel := context.withtimeout(context.background(), timeout) defer cancel() done := make(chan struct{}, 1) go func() { Do(ctx,...) done <- struct{} }() select{ case <-done: // nice... case <-ctx.done(): // timeout... } }

并发超时控制

Go 1 2 3 4 Go 1 2 3 4 Go 1 2 3 4 Go 1 2 3 4

1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 Go Go Go Go

GC

SetHistory GetHistoryByRange

SetHistory GetData Decompress Deserialize Serialize Compress SetData GetHistoryByRange Loop GetData Decompress Deserialize

GC Deserialize

Pipeline type Reader interface { } Read(p []byte) (n int, err error) type Writer interface { } Write(p []byte) (n int, err error)

Data Decompress Data Deserialize Data Data Decompress Buffer Deserialize Data Pipeline

Data Decompress Buffer Deserialize Data Pool Data Decompress Deserialize Data

Loop GetData Decompress Deserialize Go GetData Decompress Deserialize Go GetData Decompress Deserialize Go GetData Decompress Deserialize

Thread local Panic,Recover

工程性 Golang Python

import ( "go/parser" "go/token" ) fset := token.newfileset() // positions are relative to fset f, err := parser.parsefile(fset, example.go, nil, parser.allerrors)

Thanks!