[lxc-devel] [lxd/master] Performance improvements and bugfixes
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Mar 10 22:05:34 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160310/781fa79e/attachment.bin>
-------------- next part --------------
From 2ec810f87004a1b546525c47b938b71fccb2511e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 10 Mar 2016 16:43:55 -0500
Subject: [PATCH 1/2] Maintain a simplestreams cache
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #1680
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/daemon_images.go | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/lxd/daemon_images.go b/lxd/daemon_images.go
index 7aa57ca..98185d4 100644
--- a/lxd/daemon_images.go
+++ b/lxd/daemon_images.go
@@ -8,6 +8,7 @@ import (
"mime/multipart"
"os"
"path/filepath"
+ "sync"
"time"
"github.com/lxc/lxd/shared"
@@ -15,6 +16,14 @@ import (
log "gopkg.in/inconshreveable/log15.v2"
)
+type imageStreamCacheEntry struct {
+ ss *shared.SimpleStreams
+ expiry time.Time
+}
+
+var imageStreamCache = map[string]*imageStreamCacheEntry{}
+var imageStreamCacheLock sync.Mutex
+
// ImageDownload checks if we have that Image Fingerprint else
// downloads the image from a remote server.
func (d *Daemon) ImageDownload(op *operation, server string, protocol string, certificate string, secret string, alias string, forContainer bool, autoUpdate bool) (string, error) {
@@ -29,10 +38,22 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
// Expand aliases
if protocol == "simplestreams" {
- ss, err = shared.SimpleStreamsClient(server, d.proxy)
- if err != nil {
- return "", err
+ imageStreamCacheLock.Lock()
+ entry, _ := imageStreamCache[server]
+ if entry == nil || entry.expiry.Before(time.Now()) {
+ ss, err = shared.SimpleStreamsClient(server, d.proxy)
+ if err != nil {
+ imageStreamCacheLock.Unlock()
+ return "", err
+ }
+
+ entry = &imageStreamCacheEntry{ss: ss, expiry: time.Now().Add(time.Hour)}
+ imageStreamCache[server] = entry
+ } else {
+ shared.Debugf("Using SimpleStreams cache entry for %s, expires at %s", server, entry.expiry)
+ ss = entry.ss
}
+ imageStreamCacheLock.Unlock()
target := ss.GetAlias(fp)
if target != "" {
From 0d5c91f87ae95e5d8788d58b55b5821a80d6752a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 10 Mar 2016 17:04:32 -0500
Subject: [PATCH 2/2] Allow for auto-update of images coming from a LXD server
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
client.go | 8 +++++---
lxd/daemon_images.go | 4 ++++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/client.go b/client.go
index bb19b67..7decf89 100644
--- a/client.go
+++ b/client.go
@@ -1181,11 +1181,11 @@ func (c *Client) Init(name string, imgremote string, image string, profiles *[]s
if tmpremote.Remote.Protocol != "simplestreams" {
target := tmpremote.GetAlias(image)
- if target != "" {
- image = target
+ if target == "" {
+ target = image
}
- imageinfo, err := tmpremote.GetImageInfo(image)
+ imageinfo, err := tmpremote.GetImageInfo(target)
if err != nil {
return nil, err
}
@@ -1197,6 +1197,8 @@ func (c *Client) Init(name string, imgremote string, image string, profiles *[]s
if !imageinfo.Public {
var secret string
+ image = target
+
resp, err := tmpremote.post("images/"+image+"/secret", nil, Async)
if err != nil {
return nil, err
diff --git a/lxd/daemon_images.go b/lxd/daemon_images.go
index 98185d4..c05ea21 100644
--- a/lxd/daemon_images.go
+++ b/lxd/daemon_images.go
@@ -376,6 +376,10 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
// By default, make all downloaded images private
info.Public = false
+ if alias != fp && secret == "" {
+ info.AutoUpdate = autoUpdate
+ }
+
_, err = imageBuildFromInfo(d, info)
if err != nil {
shared.Log.Error(
More information about the lxc-devel
mailing list