hystrix 介绍

24
Hystrix 介绍 晓丹 2015/05/29

Upload: dennis-zhuang

Post on 15-Jan-2017

1.017 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Hystrix 介绍

Hystrix 介绍晓丹 2015/05/29

Page 2: Hystrix 介绍

What ?

• https://github.com/Netflix/Hystrix

• Hystrix is a latency and fault tolerance library designed to isolate points of access to remote systems, services and 3rd party libraries, stop cascading failure and enable resilience in complex distributed systems where failure is inevitable.

Page 3: Hystrix 介绍
Page 4: Hystrix 介绍

Why ?

• 故障是常态

• 远程服务和第三⽅方类库不可靠

• 故障蔓延,恢复延⻓长

Page 5: Hystrix 介绍
Page 6: Hystrix 介绍

How ?• Command

• Thread Pool/Semaphore

• Fallback

• Timeout

• Circuit Breaker

• ……

Page 7: Hystrix 介绍

Flow

https://raw.githubusercontent.com/wiki/Netflix/Hystrix/images/hystrix-command-flow-chart.png

Page 8: Hystrix 介绍

Basic

• Hystrix-clj

• (defcommand hello [name] (str “hello,” name))

• defcommand vs. defn

Page 9: Hystrix 介绍

Basic

• Synchronous: (hello “dennis”) => hello,dennis

• Asynchronous: (queue #’hello “dennis”)

• RxJava: (observe #’hello “dennis”) => rx.Observable

Page 10: Hystrix 介绍

Configuration(defcommand hello

{:hystrix/group-key “CloudCode”

:hystrix/command-key “beforeAction”

:hystrix/thread-pool-key “CloudCode”}

[name]

(str “hello,” name))

Page 11: Hystrix 介绍

Command Group

• Group together commands such as for reporting, alerting, dashboards, or team/library ownership.

• By default Hystrix group key to define the command thread-pool unless a separate one is defined.

Page 12: Hystrix 介绍

execution.isolation.strategy

• Thread vs. Semaphore

• coreSize/maxQueueSize vs. maxConcurrentRequests

Page 13: Hystrix 介绍

Fallback

(defcommand hello {:hystrix/fallback-fn (fn [name] (str “hello from fallback,” name))} [name] (throw (ex-info “test” {})

Page 14: Hystrix 介绍

Fallback: Primary + Secondary

Page 15: Hystrix 介绍

Request Cache

Page 16: Hystrix 介绍

Request Cache

(defcommand hello

{:hystrix/cache-fn (fn [name] name)}

[name]

(println name)

(str “hello,” name))

Page 17: Hystrix 介绍

Request Collapsing

Page 18: Hystrix 介绍

Request Collapsing(defcollapser search

"Collapsing single-term search command"

(collapse [arg-lists]

; Create a multi-search command, passing individual terms as a seq of args

(instantiate multi-search (map first arg-lists)))

(map [arg-lists batch-result]

; Map from input args to results. Here we assume order is preserve by

; multi-search so we can return the result list directly

batch-result))

(search “Something1”)

(search “Something2")

Page 19: Hystrix 介绍

Circuit Breaker

• Tripping a circuit-breaker to stop all requests to a particular service for a period of time, either manually or automatically if the error percentage for the service passes a threshold.

Page 20: Hystrix 介绍

Circuit Breaker

Page 21: Hystrix 介绍

Configuration

• Global default from code

• Dynamic global default property

• Instance default from code

• Dynamic instance property

• https://github.com/Netflix/archaius

Page 22: Hystrix 介绍

Dashboard• https://github.com/Netflix/Hystrix/wiki/Metrics-and-Monitoring

• https://github.com/Netflix/Hystrix/wiki/Dashboard

Page 23: Hystrix 介绍

Patterns• Fail Fast

• Fail Silent

• Fallback

• static

• stubbed

• cache vs. network

• Primary + secondary

• https://github.com/Netflix/Hystrix/wiki/How-To-Use#Common-Patterns

Page 24: Hystrix 介绍

The End