The default Go implementation of
sync.RWMutex does not scale well
to multiple cores, as all readers contend on the same memory location
when they all try to atomically increment it. This gist explores an
n-way RWMutex, also known as a "big reader" lock, which gives each
CPU core its own RWMutex. Readers take only a read lock local to their
core, whereas writers must take all locks in order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| My name is {{.Name}} and I'm {{.Age}} years old!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "bytes" | |
| "fmt" | |
| "github.com/gorilla/mux" | |
| grpc "github.com/gorilla/rpc" | |
| "github.com/gorilla/rpc/json" | |
| "log" | |
| "net/http" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package consumer | |
| import ( | |
| "errors" | |
| "testing" | |
| "github.com/bitly/go-nsq" | |
| ) | |
| // tests nsq.HandlerFunc. just write the function in line in the test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| // This is a basic example of running an nsqd instance embedded. It creates | |
| // and runs an nsqd with all of the default options, and then produces | |
| // and consumes a single message. You are probably better off running a | |
| // standalone instance, but embedding it can simpllify deployment. | |
| // See https://github.com/bitly/nsq/blob/master/nsqd/options.go and | |
| // https://github.com/bitly/nsq/blob/master/apps/nsqd/nsqd.go for | |
| // more details on how to configure an embedded nsqd instance. |
by 郑凯 zhengkai@gmail.com
2014.10.23
- Chrome 插件
Secure Shell
NewerOlder