-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #549 from rgooch/master
Improve performance of downloading objects and add cache to hypervisor.
- Loading branch information
Showing
25 changed files
with
1,045 additions
and
185 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"time" | ||
|
||
imgclient "github.com/Symantec/Dominator/imageserver/client" | ||
"github.com/Symantec/Dominator/lib/filesystem" | ||
"github.com/Symantec/Dominator/lib/format" | ||
"github.com/Symantec/Dominator/lib/hash" | ||
"github.com/Symantec/Dominator/lib/log" | ||
"github.com/Symantec/Dominator/lib/objectserver" | ||
) | ||
|
||
func testDownloadSpeedSubcommand(args []string) { | ||
if err := testDownloadSpeed(args[0], logger); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error testing download speed: %s\n", err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
|
||
func testDownloadSpeed(imageName string, logger log.Logger) error { | ||
imageSClient, objClient := getClients() | ||
isDir, err := imgclient.CheckDirectory(imageSClient, imageName) | ||
if err != nil { | ||
return err | ||
} | ||
if isDir { | ||
name, err := imgclient.FindLatestImage(imageSClient, imageName, false) | ||
if err != nil { | ||
return err | ||
} else { | ||
imageName = name | ||
} | ||
} | ||
startTime := time.Now() | ||
img, err := imgclient.GetImageWithTimeout(imageSClient, imageName, *timeout) | ||
if err != nil { | ||
return err | ||
} | ||
if img == nil { | ||
return errors.New(imageName + ": not found") | ||
} | ||
finishedTime := time.Now() | ||
logger.Printf("downloaded image metadata in %s\n", | ||
format.Duration(finishedTime.Sub(startTime))) | ||
hashes := make([]hash.Hash, 0, len(img.FileSystem.InodeTable)) | ||
for _, inode := range img.FileSystem.InodeTable { | ||
if inode, ok := inode.(*filesystem.RegularInode); ok { | ||
if inode.Size > 0 { | ||
hashes = append(hashes, inode.Hash) | ||
} | ||
} | ||
} | ||
startTime = time.Now() | ||
objectsReader, err := objClient.GetObjects(hashes) | ||
if err != nil { | ||
return err | ||
} | ||
defer objectsReader.Close() | ||
var totalBytes uint64 | ||
buffer := make([]byte, 32<<10) | ||
for range hashes { | ||
if length, err := readOneObject(objectsReader, buffer); err != nil { | ||
return err | ||
} else { | ||
totalBytes += length | ||
} | ||
} | ||
finishedTime = time.Now() | ||
downloadTime := finishedTime.Sub(startTime) | ||
downloadSpeed := float64(totalBytes) / downloadTime.Seconds() | ||
logger.Printf("downloaded %s (%d objects) in %s (%s/s)\n", | ||
format.FormatBytes(totalBytes), len(hashes), | ||
format.Duration(downloadTime), | ||
format.FormatBytes(uint64(downloadSpeed))) | ||
return nil | ||
} | ||
|
||
func readOneObject(objectsReader objectserver.ObjectsReader, | ||
buffer []byte) (uint64, error) { | ||
_, reader, err := objectsReader.NextObject() | ||
if err != nil { | ||
return 0, err | ||
} | ||
defer reader.Close() | ||
nCopied, err := io.CopyBuffer(ioutil.Discard, reader, buffer) | ||
return uint64(nCopied), err | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.