Jay Taylor's notes
back to listing indexchrislusf/glow
[web search]agent | reader ack connection closing | 9 days ago | |
driver | format error | 5 days ago | |
etc | update | 3 months ago | |
examples | add example for SaveTextToFile() | 4 days ago | |
flow | add buffer for slice channel | 4 days ago | |
netchan | remove windows files properly; fix map locking | 8 days ago | |
resource | add 2-way SSL to secure Glow cluster | 23 days ago | |
source | add hdfs example | 3 months ago | |
util | add 2-way SSL to secure Glow cluster | 23 days ago | |
.gitignore | working resource allocation | 5 months ago | |
.travis.yml | adding 1.6 | 15 days ago | |
Dockerfile | Dockerize word_count example | a month ago | |
LICENSE-Apache 2.0.txt | Create LICENSE-Apache 2.0.txt | 5 months ago | |
README.md | Update README.md | a month ago | |
glow.go | combine CLI options "ip" and "port" to "address" | 22 days ago |
README.md
glow
Purpose
Glow is providing a library to easily compute in parallel threads or distributed to clusters of machines.
Installation
normalgo get github.com/chrislusf/glow
go get github.com/chrislusf/glow/flow
normal
One minute tutorial
Simple Start
Here is a simple full example:
normalpackage main
import (
"flag"
"strings"
"github.com/chrislusf/glow/flow"
)
func main() {
flag.Parse()
flow.New().TextFile(
"/etc/passwd", 3,
).Filter(func(line string) bool {
return !strings.HasPrefix(line, "#")
}).Map(func(line string, ch chan string) {
for _, token := range strings.Split(line, ":") {
ch <- token
}
}).Map(func(key string) int {
return 1
}).Reduce(func(x int, y int) int {
return x + y
}).Map(func(x int) {
println("count:", x)
}).Run()
}
normal
Try it.
normal > ./word_count
normal
It will run the input text file, '/etc/passwd', in 3 go routines, filter/map/map, and then reduced to one number in one goroutine (not exactly one goroutine, but let's skip the details for now.) and print it out.
This is useful already, saving lots of idiomatic but repetitive code on channels, sync wait, etc, to fully utilize more CPU cores.
However, there is one more thing! It can run across a Glow cluster, which can be run multiple servers/racks/data centers!
Scale it out
To setup the Glow cluster, we do not need experts on Zookeeper/HDFS/Mesos/YARN etc. Just build or download one binary file.
Setup the cluster
normal // fetch and install via go, or just download it from somewhere
> go get github.com/chrislusf/glow
// start a master on one computer
> glow master
// run one or more agents on computers
> glow agent --dir . --max.executors=16 --memory=2048 --master="localhost:8930" --port 8931
normal
Glow Master and Glow Agent run very efficiently. They take about 6.5MB and 5.5MB memory respectively in my environments. I would recommend set up agents on any server you can find. You can tap into the computing power whenever you need to.
Start the driver program
To leap from one computer to clusters of computers, add this line to the import list:
normal _ "github.com/chrislusf/glow/driver"
normal
This will "steroidize" the code to run in cluster mode!
normal> ./word_count -glow -glow.leader="localhost:8930"
normal
The word_count program will become a driver program, dividing the execution into a directed acyclic graph(DAG), and send tasks to agents.
Visualize the flow
To understand how each executor works, you can visualize the flow by generating a dot file of the flow, and render it to png file via "dot" command provided from graphviz.
normal> ./word_count -glow -glow.flow.plot > x.dot
> dot -Tpng -otestSelfJoin.png x.dot
normal
Read More
- Wiki page: https://github.com/chrislusf/glow/wiki
- Mailing list: https://groups.google.com/forum/#!forum/glow-user-discussion
- Examples: https://github.com/chrislusf/glow/tree/master/examples/
Docker container
Docker is not required. But if you like docker, here are instructions.
normal// Cross compile artefact for docker
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build .
// build container
docker build -t glow .
normal
See examples/
directory for docker-compose setups.
Contribution
Start using it! And report or fix any issue you have seen, add any feature you want.
Fork it, code it, and send pull requests. Better first discuss about the feature you want on the mailing list. https://groups.google.com/forum/#!forum/glow-user-discussion