A running example of the code from:
- http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang
- http://nesv.github.io/golang/2014/02/25/worker-queues-in-go.html
Small refactorings made to original code:
| # Guide | |
| # Configure the essential configurations below and do the following: | |
| # | |
| # Repository Creation: | |
| # cap deploy:repository:create | |
| # git add . | |
| # git commit -am "initial commit" | |
| # git push origin master | |
| # | |
| # Initial Deployment: |
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
A running example of the code from:
Small refactorings made to original code:
| package main | |
| import ( | |
| "net" | |
| "os/exec" | |
| "github.com/k0kubun/pp" | |
| ) | |
| func Hosts(cidr string) ([]string, error) { |
| type ApacheLogRecord struct { | |
| http.ResponseWriter | |
| ip string | |
| time time.Time | |
| method, uri, protocol string | |
| status int | |
| responseBytes int64 | |
| elapsedTime time.Duration | |
| } |
| package main | |
| import ( | |
| "fmt" | |
| "reflect" | |
| ) | |
| type Foo struct { | |
| FirstName string `tag_name:"tag 1"` | |
| LastName string `tag_name:"tag 2"` |
| /* | |
| Parallel processing with ordered output in Go | |
| (you can use this pattern by importing https://github.com/MarianoGappa/parseq) | |
| This example implementation is useful when the following 3 conditions are true: | |
| 1) the rate of input is higher than the rate of output on the system (i.e. it queues up) | |
| 2) the processing of input can be parallelised, and overall throughput increases by doing so | |
| 3) the order of output of the system needs to respect order of input | |
| - if 1 is false, KISS! |
| /* | |
| This snippet is an example of backpressure implementation in Go. | |
| It doesn't run in Go Playground, because it starts an HTTP Server. | |
| The example starts an HTTP server and sends multiple requests to it. The server starts denying | |
| requests by replying an "X" (i.e. a 502) when its buffered channel reaches capacity. | |
| This is not the same as rate-limiting; you might be interested in https://github.com/juju/ratelimit | |
| or https://godoc.org/golang.org/x/time/rate. |
| package main | |
| import "fmt" | |
| type Node struct { | |
| prev *Node | |
| next *Node | |
| key interface{} | |
| } |