github.com/gdamore/mangos@v1.4.0/perf/main.go (about) 1 // Copyright 2015 The Mangos Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use file except in compliance with the License. 5 // You may obtain a copy of the license at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package perf provides utilities to measure mangos peformance against 16 // libnanomsg' perf tools. 17 18 package main 19 20 import ( 21 "fmt" 22 "log" 23 "os" 24 "path" 25 "strconv" 26 ) 27 28 func usage() { 29 fmt.Printf("Bad Usage!\n") 30 os.Exit(1) 31 } 32 33 func doRemoteLatency(args []string) { 34 if len(args) < 3 { 35 log.Fatalf("Usage: remote_lat <connect-to> <msg-size> <roundtrips>") 36 } 37 addr := args[0] 38 msgSize, err := strconv.Atoi(args[1]) 39 if err != nil { 40 log.Fatalf("Bad msgsize: %v", err) 41 } 42 roundTrips, err := strconv.Atoi(args[2]) 43 if err != nil { 44 log.Fatalf("Bad roundtrips: %v", err) 45 } 46 LatencyClient(addr, msgSize, roundTrips) 47 os.Exit(0) 48 } 49 50 func doLocalLatency(args []string) { 51 if len(args) < 3 { 52 log.Fatalf("Usage: local_lat <connect-to> <msg-size> <roundtrips>") 53 } 54 addr := args[0] 55 msgSize, err := strconv.Atoi(args[1]) 56 if err != nil { 57 log.Fatalf("Bad msgsize: %v", err) 58 } 59 roundTrips, err := strconv.Atoi(args[2]) 60 if err != nil { 61 log.Fatalf("Bad roundtrips: %v", err) 62 } 63 LatencyServer(addr, msgSize, roundTrips) 64 os.Exit(0) 65 } 66 67 func doRemoteThroughput(args []string) { 68 if len(args) < 3 { 69 log.Fatalf("Usage: remote_thr <connect-to> <msg-size> <msg-count>") 70 } 71 addr := args[0] 72 msgSize, err := strconv.Atoi(args[1]) 73 if err != nil { 74 log.Fatalf("Bad msg-size: %v", err) 75 } 76 msgCount, err := strconv.Atoi(args[2]) 77 if err != nil { 78 log.Fatalf("Bad msg-count: %v", err) 79 } 80 ThroughputClient(addr, msgSize, msgCount) 81 os.Exit(0) 82 } 83 84 func doLocalThroughput(args []string) { 85 if len(args) < 3 { 86 log.Fatalf("Usage: local_thr <connect-to> <msg-size> <msg-count>") 87 } 88 addr := args[0] 89 msgSize, err := strconv.Atoi(args[1]) 90 if err != nil { 91 log.Fatalf("Bad msg-size: %v", err) 92 } 93 msgCount, err := strconv.Atoi(args[2]) 94 if err != nil { 95 log.Fatalf("Bad msg-count: %v", err) 96 } 97 ThroughputServer(addr, msgSize, msgCount) 98 os.Exit(0) 99 } 100 101 func doInprocLat(args []string) { 102 if len(args) < 2 { 103 log.Fatalf("Usage: inproc_lat <msg-size> <roundtrip-count>") 104 } 105 106 size, err := strconv.Atoi(args[0]) 107 if err != nil { 108 log.Fatalf("Bad msg-size: %v", err) 109 } 110 count, err := strconv.Atoi(args[1]) 111 if err != nil { 112 log.Fatalf("Bad roundtrip-count: %v", err) 113 } 114 go LatencyServer("inproc://inproc_lat", size, count) 115 LatencyClient("inproc://inproc_lat", size, count) 116 os.Exit(0) 117 } 118 119 func doInprocThr(args []string) { 120 if len(args) < 2 { 121 log.Fatalf("Usage: inproc_thr <msg-size> <msg-count>") 122 } 123 124 size, err := strconv.Atoi(args[0]) 125 if err != nil { 126 log.Fatalf("Bad msg-size: %v", err) 127 } 128 count, err := strconv.Atoi(args[1]) 129 if err != nil { 130 log.Fatalf("Bad msg-count: %v", err) 131 } 132 go ThroughputClient("inproc://inproc_lat", size, count) 133 ThroughputServer("inproc://inproc_lat", size, count) 134 os.Exit(0) 135 } 136 137 func main() { 138 args := os.Args 139 140 tries := 0 141 for tries = 0; tries < 2; tries++ { 142 switch path.Base(args[0]) { 143 case "latency_client": 144 fallthrough 145 case "remote_lat": 146 doRemoteLatency(args[1:]) 147 148 case "latency_server": 149 fallthrough 150 case "local_lat": 151 doLocalLatency(args[1:]) 152 153 case "throughput_client": 154 fallthrough 155 case "remote_thr": 156 doRemoteThroughput(args[1:]) 157 158 case "througput_server": 159 fallthrough 160 case "local_thr": 161 doLocalThroughput(args[1:]) 162 163 case "inproc_thr": 164 doInprocThr(args[1:]) 165 166 case "inproc_lat": 167 doInprocLat(args[1:]) 168 169 default: 170 args = args[1:] 171 } 172 } 173 usage() 174 }