Skip to content

Commit

Permalink
Merge pull request #83 from jamiealquiza/jamie/score-selector
Browse files Browse the repository at this point in the history
score selection using min/max heaps
  • Loading branch information
jamiealquiza authored May 17, 2018
2 parents 53b30dd + bd2a74b commit 1fa08f7
Show file tree
Hide file tree
Showing 16 changed files with 503 additions and 509 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,29 @@ type KeyInfo struct {
}
```

### FlushMru(), FlushMfu(), FlushAll()
### FlushMRU(), FlushMFU(), FlushAll()
```go
err := c.FlushMru()
err := c.FlushMfu()
err := c.FlushMRU()
err := c.FlushMFU()
err := c.FlushAll()
```

Flush commands flush all keys from the respective cache. `FlushAll` is faster than combining `FlushMru` and `FlushMfu`.
Flush commands flush all keys from the respective cache. `FlushAll` is faster than combining `FlushMRU` and `FlushMFU`.

### Pause(), Resume()
```go
c.Pause()
c.Resume()
```

Pause and Resume allow auto evictions to be suspended and resumed, respectively. If eviction logging is enabled and evictions are paused, bicache will log accordingly.
Pause and Resume allow auto evictions to be suspended and resumed, respectively. If eviction logging is enabled and evictions are paused, bicache will log accordingly.

### Close()
```go
c.Close()
```

Close should be called when a \*Bicache is done being used, before removing any references to it, to ensure any background tasks have returned and that it can be cleanly garbage collected.

### Stats()
```go
Expand All @@ -84,10 +91,10 @@ Returns a \*bicache.Stats.

```go
type Stats struct {
MfuSize uint // Number of acive MFU keys.
MruSize uint // Number of active MRU keys.
MfuUsedP uint // MFU used in percent.
MruUsedP uint // MRU used in percent.
MFUSize uint // Number of acive MFU keys.
MRUSize uint // Number of active MRU keys.
MFUUsedP uint // MFU used in percent.
MRUUsedP uint // MRU used in percent.
Hits uint64 // Cache hits.
Misses uint64 // Cache misses.
Evictions uint64 // Cache evictions.
Expand All @@ -102,7 +109,7 @@ j, _ := json.Marshal(stats)
fmt.Prinln(string(j))
```
```
{"MfuSize":0,"MruSize":3,"MfuUsedP":0,"MruUsedP":4,"Hits":3,"Misses":0,"Evictions":0,"Overflows":0}
{"MFUSize":0,"MRUSize":3,"MFUUsedP":0,"MRUUsedP":4,"Hits":3,"Misses":0,"Evictions":0,"Overflows":0}
```

# Design
Expand Down Expand Up @@ -134,7 +141,7 @@ Tested with Go 1.7+.

### Shard counts

Shards must be sized in powers of 2. Shards are relatively inexpensive to manage but should not be arbitrarily high. Shard sizing should be relative to desired cache sizes and workload; more key space and greater write concurrency/rates are better suited with more shards. "Normal" sizes might be 8 shards for simple testing and 1024 shards for production workloads that experience tens of thousands (or more) of cache lookups a second.
Shards must be sized in powers of 2. Shards are relatively inexpensive to manage but should not be arbitrarily high. Shard sizing should be relative to desired cache sizes and workload; more key space and greater write concurrency/rates are better suited with more shards. "Normal" sizes might be 8 shards for simple testing and 1024 shards for production workloads that experience tens of thousands (or more) of cache lookups a second.

### Cache sizes

Expand Down Expand Up @@ -173,8 +180,8 @@ import (

func main() {
c, _ := bicache.New(&bicache.Config{
MfuSize: 24, // MFU capacity in keys
MruSize: 64, // MRU capacity in keys
MFUSize: 24, // MFU capacity in keys
MRUSize: 64, // MRU capacity in keys
ShardCount: 16, // Shard count. Defaults to 512 if unset.
AutoEvict: 30000, // Run TTL evictions + MRU->MFU promotions / evictions automatically every 30s.
EvictLog: true, // Emit eviction timing logs.
Expand Down Expand Up @@ -208,5 +215,5 @@ john
5535
[109 121 32 118 97 108 117 101]
{"MfuSize":0,"MruSize":3,"MfuUsedP":0,"MruUsedP":4,"Hits":3,"Misses":0,"Evictions":0,"Overflows":0}
{"MFUSize":0,"MRUSize":3,"MFUUsedP":0,"MRUUsedP":4,"Hits":3,"Misses":0,"Evictions":0,"Overflows":0}
```
Loading

0 comments on commit 1fa08f7

Please sign in to comment.