Codebase list golang-github-beorn7-perks / 45fafcf
Merge example Blake Mizerany 10 years ago
1 changed file(s) with 31 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
99 "strconv"
1010 )
1111
12 func Example() {
12 func Example_simple() {
1313 ch := make(chan float64)
1414 go readFloats(ch)
1515
3030 // count: 2388
3131 }
3232
33 func Example_mergeMultipleStreams() {
34 // Scenario:
35 // We have multiple database shards. On each shard, there is a process
36 // collecting query response times from the database logs and inserting
37 // them into a Stream (created via NewTargeted(0.90)), much like the
38 // Simple example. These processes expose a network interface for us to
39 // ask them to serialize and send us the results of their
40 // Stream.Samples so we may Merge and Query them.
41 //
42 // NOTES:
43 // * These sample sets are small, allowing us to get them
44 // across the network much faster than sending the entire list of data
45 // points.
46 //
47 // * For this to work correctly, we must supply the same quantiles
48 // a priori the process collecting the samples supplied to NewTargeted,
49 // even if we do not plan to query them all here.
50 ch := make(chan quantile.Samples)
51 getDBQuerySamples(ch)
52 q := quantile.NewTargeted(0.90)
53 for samples := range ch {
54 q.Merge(samples)
55 }
56 fmt.Println("perc50:", q.Query(0.90))
57 }
58
59 // This is a stub for the above example. In reality this would hit the remote
60 // servers via http or something like it.
61 func getDBQuerySamples(ch chan quantile.Samples) {}
62
3363 func readFloats(ch chan<- float64) {
3464 f, err := os.Open("exampledata.txt")
3565 if err != nil {