Skip to content

Commit ef121c7

Browse files
author
Matthew Fisher
committed
Merge pull request #1858 from johanneswuerbach/lru-cache
feat(registry): deis-cache for saving meta data
2 parents ea8ef5c + e8b61f8 commit ef121c7

3 files changed

Lines changed: 52 additions & 10 deletions

File tree

cache/image/main.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
package main
22

33
import (
4+
"io/ioutil"
45
"log"
56
"net"
67
"os"
78
"os/exec"
89
"os/signal"
10+
"strings"
911
"syscall"
1012
"time"
1113

1214
"github.com/coreos/go-etcd/etcd"
1315
)
1416

1517
const (
16-
timeout time.Duration = 10 * time.Second
17-
ttl time.Duration = timeout * 2
18-
redisWait time.Duration = 5 * time.Second
18+
timeout time.Duration = 10 * time.Second
19+
ttl time.Duration = timeout * 2
20+
redisWait time.Duration = 5 * time.Second
21+
redisConf string = "/app/redis.conf"
22+
ectdKeyNotFound int = 100
23+
defaultMemory string = "50mb"
1924
)
2025

2126
func main() {
@@ -28,6 +33,19 @@ func main() {
2833

2934
client := etcd.NewClient([]string{"http://" + host + ":" + etcdPort})
3035

36+
var maxmemory string
37+
result, err := client.Get("/deis/cache/maxmemory", false, false)
38+
if err != nil {
39+
if e, ok := err.(*etcd.EtcdError); ok && e.ErrorCode == ectdKeyNotFound {
40+
maxmemory = defaultMemory
41+
} else {
42+
log.Fatalln(err)
43+
}
44+
} else {
45+
maxmemory = result.Node.Key
46+
}
47+
replaceMaxmemoryInConfig(maxmemory)
48+
3149
go launchRedis()
3250

3351
go publishService(client, host, etcdPath, externalPort, uint64(ttl.Seconds()))
@@ -38,8 +56,20 @@ func main() {
3856
<-exitChan
3957
}
4058

59+
func replaceMaxmemoryInConfig(maxmemory string) {
60+
input, err := ioutil.ReadFile(redisConf)
61+
if err != nil {
62+
log.Fatalln(err)
63+
}
64+
output := strings.Replace(string(input), "# maxmemory <bytes>", "maxmemory "+maxmemory, 1)
65+
err = ioutil.WriteFile(redisConf, []byte(output), 0644)
66+
if err != nil {
67+
log.Fatalln(err)
68+
}
69+
}
70+
4171
func launchRedis() {
42-
cmd := exec.Command("/app/bin/redis-server", "/app/redis.conf")
72+
cmd := exec.Command("/app/bin/redis-server", redisConf)
4373
cmd.Stdout = os.Stdout
4474
cmd.Stderr = os.Stderr
4575

docs/customizing_deis/cache_settings.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ setting description
2828

2929
Settings used by cache
3030
----------------------
31-
The cache component uses no keys from etcd.
31+
32+
.. important::
33+
34+
All changes require a restart.
35+
36+
37+
The following etcd keys are used by the cache component.
38+
39+
==================================== =============================================================================================================================================================================================
40+
setting description
41+
==================================== =============================================================================================================================================================================================
42+
/deis/cache/maxmemory maximum memory used for caching (default: 50mb)
43+
==================================== =============================================================================================================================================================================================
3244

3345
Using a custom cache image
3446
--------------------------

registry/templates/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ common: &common
3434
# Enabling LRU cache for small files
3535
# This speeds up read/write on small files
3636
# when using a remote storage backend (like S3).
37-
# cache_lru:
38-
# host: _env:CACHE_LRU_REDIS_HOST:localhost
39-
# port: _env:CACHE_LRU_REDIS_PORT:6379
40-
# db: 0
41-
# password: _env:CACHE_LRU_REDIS_PASSWORD
37+
cache_lru:
38+
host: {{ or (.deis_cache_host) "~" }}
39+
port: {{ or (.deis_cache_port) "~" }}
40+
password: _env:CACHE_LRU_REDIS_PASSWORD
41+
db: 2
4242

4343
# Enabling these options makes the Registry send an email on each code Exception
4444
{{ if .deis_registry_smtpHost }}

0 commit comments

Comments
 (0)