go.uber.org/yarpc@v1.72.1/internal/stresstest/main.go (about)

     1  // Copyright (c) 2022 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  // Package main runs a stress test on each peer list implementation,
    22  // concurrently adding, removing, connecting, disconnecting, and choosing
    23  // peers.
    24  //
    25  // Output:
    26  //
    27  //  name                     stress  workers  min       max         mean       choices  updates
    28  //  round-robin              true    1        245       8770915     146851     5253     46150
    29  //  round-robin              false   1        207       418011      291        971224   1
    30  //  round-robin              true    10       233       16849329    387306     19074    50669
    31  //  round-robin              false   10       223       1578697     5346       1194757  1
    32  //  round-robin              true    100      230       27465221    908544     75258    46810
    33  //  round-robin              false   100      226       7461220     67418      1032094  1
    34  //  round-robin              true    1000     233       22398858    2024969    330804   4576
    35  //  round-robin              false   1000     229       21501281    802412     839121   1
    36  //  round-robin              true    10000    233       92130003    19808992   346389   297
    37  //  round-robin              false   10000    276       64225586    21145554   314307   1
    38  //  round-robin              true    100000   230       938109206   206172150  420222   8
    39  //  round-robin              false   100000   234       752404056   162852049  555573   1
    40  //  random                   true    1        290       9613482     147458     5411     51211
    41  //  random                   false   1        218       4010623     320        945794   1
    42  //  random                   true    10       251       13586138    292117     25511    51602
    43  //  random                   false   10       234       6359156     6460       945427   1
    44  //  random                   true    100      245       22698254    635979     106915   41375
    45  //  random                   false   100      245       11036988    90960      740277   1
    46  //  random                   true    1000     248       16201139    1991433    335656   8817
    47  //  random                   false   1000     241       20870812    1309373    510240   1
    48  //  random                   true    10000    289       78923469    23178028   288479   125
    49  //  random                   false   10000    297       80162200    24015477   278955   1
    50  //  random                   true    100000   241       765837860   237899834  351979   25
    51  //  random                   false   100000   289       694941549   212820591  365262   1
    52  //  fewest-pending-requests  true    1        390       4419885     224512     3200     45697
    53  //  fewest-pending-requests  false   1        313       1388333     437        811476   1
    54  //  fewest-pending-requests  true    10       341       15878684    238641     29821    38477
    55  //  fewest-pending-requests  false   10       328       5097597     8860       719393   1
    56  //  fewest-pending-requests  true    100      338       12701474    452931     150094   35696
    57  //  fewest-pending-requests  false   100      339       9182151     96564      705745   1
    58  //  fewest-pending-requests  true    1000     329       13381772    2351399    285263   1816
    59  //  fewest-pending-requests  false   1000     312       16021295    1546288    430947   1
    60  //  fewest-pending-requests  true    10000    421       85027409    29813414   227209   135
    61  //  fewest-pending-requests  false   10000    404       86757606    27587847   244877   1
    62  //  fewest-pending-requests  true    100000   381       969925927   278125286  320719   11
    63  //  fewest-pending-requests  false   100000   342       759484399   256068224  351255   1
    64  //  two-random-choices       true    1        296       12530130    167011     4873     56520
    65  //  two-random-choices       false   1        234       2157414     331        973400   1
    66  //  two-random-choices       true    10       257       14773053    264627     27980    49152
    67  //  two-random-choices       false   10       254       6038348     6769       896344   1
    68  //  two-random-choices       true    100      264       16509807    566482     120169   47062
    69  //  two-random-choices       false   100      265       8954712     78887      840535   1
    70  //  two-random-choices       true    1000     262       16153194    1959869    341938   6304
    71  //  two-random-choices       false   1000     257       14265730    1299014    512357   1
    72  //  two-random-choices       true    10000    312       65980563    25155737   263431   75
    73  //  two-random-choices       false   10000    315       68347456    23842068   282351   1
    74  //  two-random-choices       true    100000   259       1164075075  114441088  663750   31
    75  //  two-random-choices       false   100000   269       836529911   164734573  545225   1
    76  package main
    77  
    78  import (
    79  	"fmt"
    80  	"time"
    81  
    82  	"go.uber.org/yarpc/api/peer"
    83  	"go.uber.org/yarpc/peer/pendingheap"
    84  	"go.uber.org/yarpc/peer/randpeer"
    85  	"go.uber.org/yarpc/peer/roundrobin"
    86  	"go.uber.org/yarpc/peer/tworandomchoices"
    87  	"go.uber.org/yarpc/yarpctest"
    88  )
    89  
    90  func main() {
    91  	fmt.Printf("name,stress,workers,min,max,mean,choices,updates\n")
    92  	log := logger{}
    93  	for _, c := range []struct {
    94  		name    string
    95  		newFunc func(peer.Transport) peer.ChooserList
    96  	}{
    97  		{
    98  			name: "round-robin",
    99  			newFunc: func(trans peer.Transport) peer.ChooserList {
   100  				return roundrobin.New(trans)
   101  			},
   102  		},
   103  		{
   104  			name: "random",
   105  			newFunc: func(trans peer.Transport) peer.ChooserList {
   106  				return randpeer.New(trans)
   107  			},
   108  		},
   109  		{
   110  			name: "fewest-pending-requests",
   111  			newFunc: func(trans peer.Transport) peer.ChooserList {
   112  				return pendingheap.New(trans)
   113  			},
   114  		},
   115  		{
   116  			name: "two-random-choices",
   117  			newFunc: func(trans peer.Transport) peer.ChooserList {
   118  				return tworandomchoices.New(trans)
   119  			},
   120  		},
   121  	} {
   122  		for i := 1; i <= 1000; i *= 10 {
   123  			for _, lowStress := range []bool{false, true} {
   124  				report := yarpctest.ListStressTest{
   125  					Workers:   i,
   126  					Duration:  time.Second,
   127  					Timeout:   time.Millisecond * time.Duration(i),
   128  					LowStress: lowStress,
   129  					New:       c.newFunc,
   130  				}.Run(log)
   131  				if report.Choices != 0 {
   132  					fmt.Printf("%s,%v,%d,%d,%d,%d,%d,%d\n",
   133  						c.name,
   134  						!lowStress,
   135  						uint64(i),
   136  						uint64(report.Min),
   137  						uint64(report.Max),
   138  						uint64(report.Total/time.Duration(report.Choices)),
   139  						report.Choices,
   140  						report.Updates,
   141  					)
   142  				}
   143  			}
   144  		}
   145  	}
   146  }
   147  
   148  type logger struct{}
   149  
   150  func (logger) Logf(format string, args ...interface{}) {
   151  	fmt.Printf(format, args...)
   152  }