singleflight

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2019 License: MIT Imports: 10 Imported by: 0

README

singleflight

当多个完全相同请求同时访问时,只会有一个请求“真正”执行方法,其他请求返回相同结果

性能

  • 未使用 singleflight
$ wrk -t100 -c100 -d30 -T30s -H "X-Fly: abc" --latency http://127.0.0.1:9091/original
Running 30s test @ http://127.0.0.1:9091/original
  100 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    22.09ms    1.77ms  35.51ms   82.77%
    Req/Sec    45.20      5.18    58.00     57.97%
  Latency Distribution
     50%   21.50ms
     75%   22.79ms
     90%   24.48ms
     99%   28.37ms
  135954 requests in 30.11s, 23.56MB read
Requests/sec:   4515.89
Transfer/sec:    801.31KB

$ curl 127.0.0.1:9091/count
136043
  • 使用 singleflight
$ wrk -t100 -c100 -d30 -T30s -H "X-Fly: abc" --latency http://127.0.0.1:9091/single
Running 30s test @ http://127.0.0.1:9091/single
  100 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    24.05ms    2.30ms  34.55ms   68.62%
    Req/Sec    41.47      4.45    50.00     77.04%
  Latency Distribution
     50%   23.84ms
     75%   25.55ms
     90%   27.18ms
     99%   29.83ms
  124874 requests in 30.08s, 21.65MB read
Requests/sec:   4151.59
Transfer/sec:    737.21KB

$ curl 127.0.0.1:9091/count
1251

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group interface {
	Do(next http.Handler, opts ...Option) http.Handler
}

Group group

func New added in v0.1.1

func New() Group

New new group

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option option

func WithExceptHeader added in v0.1.2

func WithExceptHeader(header ...string) Option

WithExceptHeader 排除 header 列表,例如每个请求的 call-id

func WithHeader

func WithHeader(name, value string) Option

WithHeader 只有 name 和 value 都符合的请求才会被执行 name 和 value 任意为空都不会执行

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL