Skip to content

Commit

Permalink
swarm --> sprinkle
Browse files Browse the repository at this point in the history
  • Loading branch information
dmah42 committed May 31, 2022
1 parent 9df83a2 commit 618eb9e
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 114 deletions.
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ ui: $(OUT)/ui
.PHONY: clean
clean:
@rm $(OUT)/*
@rm api/swarm/*.pb.go
@rm api/sprinkle/*.pb.go

# go generate ./api/swarm
api/swarm/*.pb.go: ./api/swarm/swarm.proto
api/sprinkle/*.pb.go: ./api/sprinkle/sprinkle.proto
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative $<

$(OUT)/worker: internal/*.go api/swarm/*.pb.go cmd/worker/*.go
$(OUT)/worker: internal/*.go api/sprinkle/*.pb.go cmd/worker/*.go
mkdir -p $(OUT)
go build -o $@ ./cmd/worker

$(OUT)/run: internal/*.go api/swarm/*.pb.go cmd/run/*.go
$(OUT)/run: internal/*.go api/sprinkle/*.pb.go cmd/run/*.go
mkdir -p $(OUT)
go build -o $@ ./cmd/run

$(OUT)/ui: internal/*.go api/swarm/*.pb.go cmd/ui/*.go cmd/ui/*.html
$(OUT)/ui: internal/*.go api/sprinkle/*.pb.go cmd/ui/*.go cmd/ui/*.html
mkdir -p $(OUT)
go build -o $@ ./cmd/ui
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# Swarm
# Sprinkle
Run jobs on distributed machines easily. No master negotiation or consensus in
sight: All parts take an `addr` command line argument that refers to a UDP
multicast address on which workers can be discovered.

## Commands
### Worker
Responsible for doing work. Exposes a gRPC service definition defined in
api/proto/swarm.proto.
api/proto/sprinkle.proto.

### Swarm
User-facing command line for running work on a swarm.
### Run
User-facing command line for running work on the most appropriate worker.

### UI
Simple HTTP server to monitor the swarm.
Simple HTTP server to monitor the workers and running jobs.

## Example command lines
Start the UI
```
$ ./bin/ui --logtostderr --addr="225.0.0.1:9999"
$ ./bin/ui --logtostderr"
```

Start a worker
```
$ ./bin/worker --logtostderr --addr="225.0.0.1:9999"
$ ./bin/worker --logtostderr"
```

Run a command
```
$ ./bin/swarm --cmd="echo hello" --logtostderr --addr=225.0.0.1:9999
$ ./bin/run --cmd="sleep 10 && echo hello" --logtostderr
...
I0103 10:13:41.607985 14308 swarm.go:224] hello
hello
```

## TODO
Expand Down
4 changes: 2 additions & 2 deletions api/swarm/swarm.proto → api/sprinkle/sprinkle.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";

option go_package = "github.com/dominichamon/swarm/api/swarm";
option go_package = "github.com/dominichamon/sprinkle/api/sprinkle";

package swarm;
package sprinkle;

message StatusRequest {}

Expand Down
4 changes: 2 additions & 2 deletions cmd/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"strconv"
"time"

"github.com/dominichamon/swarm/internal"
"github.com/dominichamon/sprinkle/internal"
"github.com/golang/glog"
"golang.org/x/net/context"

pb "github.com/dominichamon/swarm/api/swarm"
pb "github.com/dominichamon/sprinkle/api/sprinkle"
)

var (
Expand Down
164 changes: 88 additions & 76 deletions cmd/ui/index.html
Original file line number Diff line number Diff line change
@@ -1,90 +1,102 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="10">
<title>swarm</title>

<style>
body {
background-color: black;
background-image: radial-gradient(
rgba(0, 150, 0, 0.75), black 120%
);
height: 100vh;
color: white;
font-family: "Andale Mono", Courier, monospace;
text-shadow: 0 0 5px #C8C8C8;
}
<head>
<meta http-equiv="refresh" content="10">
<title>sprinkle</title>

body::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: repeating-linear-gradient(
0deg,
<style>
body {
background-color: black;
background-image: radial-gradient(rgba(0, 150, 0, 0.75), black 120%);
height: 100vh;
color: white;
font-family: "Andale Mono", Courier, monospace;
text-shadow: 0 0 5px #C8C8C8;
}

body::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: repeating-linear-gradient(0deg,
black 25%,
black 25% 2px,
transparent 2px,
transparent 4px);
}
}

::selection {
background: #0080FF;
text-shadow: none;
}

table {
table-layout: auto;
width: 80%;
border-collapse: collapse;
border: 2px dashed;
}

::selection {
background: #0080FF;
text-shadow: none;
}
th,
td {
padding: 20px;
}

table {
table-layout: auto;
width: 80%;
border-collapse: collapse;
border: 2px dashed;
}
tbody td {
text-align: center;
}

th, td {
padding: 20px;
}
th {
border-bottom: 1px solid;
}
</style>
</head>

tbody td {
text-align: center;
}
<body>
<h1>sprinkle</h1>
<h2>status</h2>
<table>
<thead>
<th>Id</th>
<th>IP</th>
<th>Host</th>
<th>Total RAM (GB)</th>
<th>Free RAM (GB)</th>
</thead>
{{range $id, $status := .Status}}
<tr>
<td>{{$id}}</td>
<td>{{$status.Ip}}</td>
<td>{{$status.Hostname}}</td>
<td>{{toGB $status.TotalRam}}</td>
<td>{{toGB $status.FreeRam}}</td>
</tr>
{{end}}
</table>

th {
border-bottom: 1px solid;
}
</style>
</head>
<body>
<h1>swarm</h1>
<h2>status</h2>
<table>
<thead><th>Id</th><th>IP</th><th>Host</th><th>Total RAM (GB)</th><th>Free RAM (GB)</th></thead>
{{range $id, $status := .Status}}
<tr>
<td>{{$id}}</td>
<td>{{$status.Ip}}</td>
<td>{{$status.Hostname}}</td>
<td>{{toGB $status.TotalRam}}</td>
<td>{{toGB $status.FreeRam}}</td>
</tr>
{{end}}
</table>
<h2>jobs</h2>
<table>
<thead>
<th>Id</th>
<th>Start time</th>
<th>Exited</th>
<th>Success</th>
</thead>
{{range $id, $jobs := .Jobs}}
{{range $_, $job := $jobs}}
<tr>
<td>{{$id}}</td>
<td>{{$job.StartTime}}</td>
<td>{{$job.Exited}}</td>
<td>{{$job.Success}}</td>
</tr>
{{end}}
{{end}}
</table>
</body>

<h2>jobs</h2>
<table>
<thead><th>Id</th><th>Start time</th><th>Exited</th><th>Success</th></thead>
{{range $id, $jobs := .Jobs}}
{{range $_, $job := $jobs}}
<tr>
<td>{{$id}}</td>
<td>{{$job.StartTime}}</td>
<td>{{$job.Exited}}</td>
<td>{{$job.Success}}</td>
</tr>
{{end}}
{{end}}
</table>
</body>
</html>
</html>
20 changes: 10 additions & 10 deletions cmd/ui/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package ui defines a UI for visualizing a swarm.
// Package ui defines a UI for visualizing a set of workers and the jobs running on them.
package main

import (
Expand All @@ -13,32 +13,32 @@ import (
"sync"
"time"

"github.com/dominichamon/swarm/internal"
"github.com/dominichamon/sprinkle/internal"
"github.com/golang/glog"
"golang.org/x/net/context"

pb "github.com/dominichamon/swarm/api/swarm"
pb "github.com/dominichamon/sprinkle/api/sprinkle"
)

var (
port = flag.Int("port", 1248, "The port on which to listen for HTTP")
poll = flag.Duration("poll", 1*time.Minute, "The time to wait between discovery attempts")
port = flag.Int("port", 1248, "The port on which to listen for HTTP")
poll = flag.Duration("poll", 1*time.Minute, "The time to wait between discovery attempts")
statusPoll = flag.Duration("status_poll", 10*time.Second, "The time to wait between status updates")

addr = flag.String("addr", "239.192.0.1:9999", "The multicast address to use for discovery")
addr = flag.String("addr", "239.192.0.1:9999", "The multicast address to use for discovery")
dport = flag.Int("dport", 9997, "The port on which to listen for discovery")

worker workerMap
status statusMap
jobs jobsMap

//go:embed index.html
embedFS embed.FS
embedFS embed.FS
indexTmpl *template.Template

funcMap = template.FuncMap {
"toGB": func (bytes uint64) string {
return fmt.Sprintf("%.3f", float64(bytes) / (1000*1000*1000))
funcMap = template.FuncMap{
"toGB": func(bytes uint64) string {
return fmt.Sprintf("%.3f", float64(bytes)/(1000*1000*1000))
},
}
)
Expand Down
10 changes: 5 additions & 5 deletions cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"fmt"
"net"

"github.com/dominichamon/swarm/internal"
"github.com/dominichamon/sprinkle/internal"
"github.com/golang/glog"
"google.golang.org/grpc"

pb "github.com/dominichamon/swarm/api/swarm"
pb "github.com/dominichamon/sprinkle/api/sprinkle"
)

var (
port = flag.Int("port", 5432, "The port on which to listen for RPC requests")
addr = flag.String("addr", "239.192.0.1:9999", "The multicast address to use for discovery")
port = flag.Int("port", 5432, "The port on which to listen for RPC requests")
addr = flag.String("addr", "239.192.0.1:9999", "The multicast address to use for discovery")
iface = flag.String("iface", "", "The interface on which to listen for pings. Defaults to first that supports multicast if unset")
)

Expand All @@ -26,7 +26,7 @@ func multicastInterface() (*net.Interface, error) {
if err != nil {
return nil, err
}
if ifi.Flags & net.FlagMulticast == 0 {
if ifi.Flags&net.FlagMulticast == 0 {
return nil, fmt.Errorf("iface %q does not support multicast", *iface)
}
return ifi, nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/worker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"syscall"
"time"

"github.com/dominichamon/swarm/internal"
"github.com/dominichamon/sprinkle/internal"
"github.com/golang/glog"
"github.com/mackerelio/go-osstat/loadavg"
"github.com/mackerelio/go-osstat/memory"
"golang.org/x/net/context"

pb "github.com/dominichamon/swarm/api/swarm"
pb "github.com/dominichamon/sprinkle/api/sprinkle"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/dominichamon/swarm
module github.com/dominichamon/sprinkle

go 1.18

Expand Down
2 changes: 1 addition & 1 deletion internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"google.golang.org/grpc"

pb "github.com/dominichamon/swarm/api/swarm"
pb "github.com/dominichamon/sprinkle/api/sprinkle"
)

type Worker struct {
Expand Down

0 comments on commit 618eb9e

Please sign in to comment.