Commit 8ea12c09 authored by Weixin Deng's avatar Weixin Deng
Browse files

Adjust args

parent f0787dac
go run ../src/service.go \
-client \
-addr "10.0.0.1" \
-numServers 4 \
-servers "10.0.0.2:9001 10.0.0.3:9001 10.0.0.4:9001 10.0.0.5:9001 10.0.0.2:9002 10.0.0.3:9002 10.0.0.4:9002 10.0.0.5:9002 10.0.0.2:9003 10.0.0.3:9003 10.0.0.4:9003 10.0.0.5:9003 10.0.0.2:9004 10.0.0.3:9004 10.0.0.4:9004 10.0.0.5:9004 10.0.0.2:9005 10.0.0.3:9005 10.0.0.4:9005 10.0.0.5:9005 10.0.0.2:9006 10.0.0.3:9006 10.0.0.4:9006 10.0.0.5:9006 10.0.0.2:9007 10.0.0.3:9007 10.0.0.4:9007 10.0.0.5:9007 10.0.0.2:9008 10.0.0.3:9008 10.0.0.4:9008 10.0.0.5:9008 " \
-numPorts 8
-numServers 8 \
-dataSize 1 \
-serverDelay 0 \
-repeat 10
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
cd
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://gitlab.cs.washington.edu/weixin/rpc-incast.git
wget https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
......
go run ../src/service.go \
-server \
-addr "10.0.0.2" \
-numPorts 8 \
-ports "9001 9002 9003 9004 9005 9006 9007 9008"
-numPorts 8
......@@ -6,11 +6,84 @@ import (
"log"
"net"
"net/rpc"
"strconv"
"strings"
"sync"
"time"
)
func Assert(assert bool, msg string) {
if !assert {
log.Fatal(msg)
}
}
type Args struct {
startServer bool
startClient bool
addr string
numPorts int
ports []string
numServers int
servers []string
dataSize int
serverDelay int
repeat int
}
func parseArgs() Args {
var startServer = flag.Bool("server", false, "Start server")
var startClient = flag.Bool("client", false, "Start client")
var addr = flag.String("addr", "localhost", "Address")
var numPorts = flag.Int("numPorts", 1, "Number of ports")
var ports = flag.String("ports", "9001", "Ports")
var numServers = flag.Int("numServers", 1, "Number of servers")
var servers = flag.String("servers", "localhost:9001", "Servers")
var dataSize = flag.Int("dataSize", 1, "Data size")
var serverDelay = flag.Int("serverDelay", 0, "Server delay in microseconds")
var repeat = flag.Int("repeat", 1, "Repeat")
flag.Parse()
args := Args{
startServer: *startServer,
startClient: *startClient,
addr: *addr,
numPorts: *numPorts,
numServers: *numServers,
dataSize: *dataSize,
serverDelay: *serverDelay,
repeat: *repeat,
}
if len(*ports) > 0 {
args.ports = strings.Fields(*ports)
} else {
var ports []string
for i := 0; i < *numPorts; i++ {
port := strconv.Itoa(9000 + i + 1)
ports = append(ports, port)
}
args.ports = ports
}
Assert(len(args.ports) == args.numPorts,
"numPorts is not equal to the number of ports")
if len(*servers) > 0 {
args.servers = strings.Fields(*servers)
} else {
numBackends := *numServers / *numPorts
var servers []string
for i := 0; i < numBackends; i++ {
backendAddr := "10.0.0." + strconv.Itoa(i+2)
for j := 0; j < *numPorts; j++ {
serverAddr := backendAddr + ":" + args.ports[j]
servers = append(servers, serverAddr)
}
}
args.servers = servers
}
Assert(len(args.servers) == args.numServers,
"numServers is not equal to the number of servers")
return args
}
type Request struct {
srcAddr string
dstAddr string
......@@ -25,17 +98,17 @@ type Reply struct {
ServerDelay time.Duration
}
type Timer struct {
type Clock struct {
Start time.Time
End time.Time
Duration time.Duration
}
func (t *Timer) Record() {
func (t *Clock) Record() {
t.Start = time.Now()
}
func (t *Timer) Stop() {
func (t *Clock) Stop() {
t.End = time.Now()
t.Duration = t.End.Sub(t.Start)
}
......@@ -44,7 +117,7 @@ type Client struct {
addr string
}
func (c *Client) SendRequest(request Request, timer *Timer, wg *sync.WaitGroup) {
func (c *Client) SendRequest(request Request, clock *Clock, wg *sync.WaitGroup) {
defer wg.Done()
client, err := rpc.Dial("tcp", request.dstAddr)
if err != nil {
......@@ -52,12 +125,12 @@ func (c *Client) SendRequest(request Request, timer *Timer, wg *sync.WaitGroup)
}
defer client.Close()
var reply Reply
timer.Record()
clock.Record()
err = client.Call("Server.HandleRequest", request, &reply)
if err != nil {
log.Fatal("[Client error] ", err)
}
timer.Stop()
clock.Stop()
}
type Server struct {
......@@ -84,90 +157,82 @@ func (s *Server) Start() {
}
func (s *Server) HandleRequest(request Request, reply *Reply) error {
var timer Timer
timer.Record()
var clock Clock
clock.Record()
*reply = Reply{
srcAddr: request.dstAddr,
dstAddr: request.srcAddr,
Data: s.data[:request.DataSize],
}
time.Sleep(request.ServerDelay)
timer.Stop()
reply.ServerDelay = timer.Duration
clock.Stop()
reply.ServerDelay = clock.Duration
return nil
}
func main() {
var startServer = flag.Bool("server", false, "Start server")
var startClient = flag.Bool("client", false, "Start client")
var addr = flag.String("addr", "localhost", "Address")
var numPorts = flag.Int("numPorts", 1, "Number of ports")
var ports = flag.String("ports", "9001", "Ports")
var numServers = flag.Int("numServers", 1, "Number of servers")
var servers = flag.String("servers", "localhost:9001", "Servers")
var dataSize = flag.Int("dataSize", 0, "Data size")
var serverDelay = flag.Int("serverDelay", 0, "Server delay in microseconds")
var repeat = flag.Int("repeat", 1, "Repeat")
flag.Parse()
if *numPorts > len(*ports) {
log.Fatal("numPorts is larger than number of ports")
func startClient(args *Args) {
client := Client{
addr: args.addr,
}
if *numServers > len(*servers) {
log.Fatal("numServers is larger than number of servers")
request := Request{
srcAddr: client.addr,
DataSize: args.dataSize,
ServerDelay: time.Duration(args.serverDelay) * time.Microsecond,
}
if *startClient {
servers := strings.Fields(*servers)
for r := 0; r < *repeat; r++ {
client := Client{
addr: *addr,
}
request := Request{
srcAddr: client.addr,
DataSize: *dataSize,
ServerDelay: time.Duration(*serverDelay) * time.Microsecond,
}
timers := make([]Timer, *numServers)
var wg sync.WaitGroup
for i := 0; i < *numServers; i++ {
wg.Add(1)
request.dstAddr = servers[i]
go client.SendRequest(request, &timers[i], &wg)
}
wg.Wait()
var start time.Time
var end time.Time
var delayAvg time.Duration
var delayTotal time.Duration
for i := 0; i < *numServers; i++ {
timer := timers[i]
if start.IsZero() || timer.Start.Before(start) {
start = timer.Start
}
if end.IsZero() || timer.End.After(end) {
end = timer.End
}
delayAvg += timer.Duration
}
delayAvg /= time.Duration(*numServers)
delayTotal = end.Sub(start)
dataSizeTotal := *dataSize * 8 * *numServers
throughput := int64(dataSizeTotal) * 1e9 / delayTotal.Nanoseconds()
fmt.Printf("DelayAvg: %s\n", delayAvg)
fmt.Printf("DelayTotal: %s\n", delayTotal)
fmt.Printf("Throughput: %dbps\n", throughput)
fmt.Println()
time.Sleep(1 * time.Second)
clocks := make([]Clock, args.numServers)
var wg sync.WaitGroup
for i := 0; i < args.numServers; i++ {
wg.Add(1)
request.dstAddr = args.servers[i]
go client.SendRequest(request, &clocks[i], &wg)
}
wg.Wait()
var start time.Time
var end time.Time
var delayAvg time.Duration
var delayTotal time.Duration
for i := 0; i < args.numServers; i++ {
clock := clocks[i]
if start.IsZero() || clock.Start.Before(start) {
start = clock.Start
}
} else if *startServer {
ports := strings.Fields(*ports)
for i := 0; i < *numPorts; i++ {
addr := *addr + ":" + ports[i]
server := Server{
addr: addr,
}
go server.Start()
if end.IsZero() || clock.End.After(end) {
end = clock.End
}
delayAvg += clock.Duration
}
delayAvg /= time.Duration(args.numServers)
delayTotal = end.Sub(start)
dataSizeTotal := args.dataSize * 8 * args.numServers
throughput := int64(dataSizeTotal) * 1e9 / delayTotal.Nanoseconds()
fmt.Printf("DelayAvg: %s\n", delayAvg)
fmt.Printf("DelayTotal: %s\n", delayTotal)
fmt.Printf("Throughput: %dbps\n", throughput)
fmt.Println()
time.Sleep(1 * time.Second)
}
func startServer(args *Args) {
var wg sync.WaitGroup
wg.Add(1)
for i := 0; i < args.numPorts; i++ {
addr := args.addr + ":" + args.ports[i]
server := Server{
addr: addr,
}
for {
go server.Start()
}
wg.Wait()
}
func main() {
args := parseArgs()
if args.startClient {
for i := 0; i < args.repeat; i++ {
startClient(&args)
}
}
if args.startServer {
startServer(&args)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment