MCPcopy Create free account
hub / github.com/appleboy/loadbalancer-algorithms / ExampleRoundRobin

Function ExampleRoundRobin

weighted/weighted_test.go:55–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53}
54
55func ExampleRoundRobin() {
56 r, _ := New()
57 for _, server := range servers {
58 _ = r.AddServer(server.url, server.weight)
59 }
60
61 fmt.Println(r.NextServer().Host)
62 fmt.Println(r.NextServer().Host)
63 fmt.Println(r.NextServer().Host)
64 fmt.Println(r.NextServer().Host)
65 fmt.Println(r.NextServer().Host)
66 fmt.Println(r.NextServer().Host)
67 fmt.Println(r.NextServer().Host)
68 fmt.Println(r.NextServer().Host)
69 fmt.Println(r.NextServer().Host)
70
71 // Output:
72 // 192.168.1.10
73 // 192.168.1.10
74 // 192.168.1.11
75 // 192.168.1.10
76 // 192.168.1.11
77 // 192.168.1.12
78 // 192.168.1.10
79 // 192.168.1.11
80 // 192.168.1.12
81}
82
83func BenchmarkNext(b *testing.B) {
84 r, _ := New()

Callers

nothing calls this directly

Calls 3

NewFunction · 0.70
AddServerMethod · 0.65
NextServerMethod · 0.65

Tested by

no test coverage detected