diff --git a/client/deploy.go b/client/deploy.go index 5774a4e..33432fd 100644 --- a/client/deploy.go +++ b/client/deploy.go @@ -23,6 +23,24 @@ import ( "golang.org/x/text/transform" ) +func pof2(x int64, min int64) (out int64) { + out = 1 + org := x + for (x >> 1) > 0 { + out = out << 1 + x = x >> 1 + } + if org > out { + out = out << 1 + } + + if out < min { + out = min + } + + return +} + func download(dir string, urlpath string, accessToken string, cb func(int64, int64)) (target string, err error) { logger.Println("start downloading", dir, urlpath) defer func() { @@ -59,13 +77,13 @@ func download(dir string, urlpath string, accessToken string, cb func(int64, int cl := resp.Header.Get("Content-Length") totalLength, _ := strconv.ParseInt(cl, 10, 0) totalWritten := int64(0) - + chunkSize := pof2(totalLength/100, 1024*1024) if cb != nil { cb(0, totalLength) } for { - written, err := io.CopyN(out, resp.Body, 1024*1024) + written, err := io.CopyN(out, resp.Body, chunkSize) totalWritten += written if cb != nil { cb(totalWritten, totalLength) @@ -324,7 +342,7 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.Deplo } cb(&protos.DeployingProgress{ - State: "unzip/untar", + State: "unpack", Progress: 0, Total: 0, }) diff --git a/client/deploy_test.go b/client/deploy_test.go index 9ca853a..9e333d1 100644 --- a/client/deploy_test.go +++ b/client/deploy_test.go @@ -1,9 +1,27 @@ package client import ( + "fmt" "testing" ) -func TestDownload(t *testing.T) { - download(".", "https://kdcc.action2quare.com/houston/_deploys/game/0.18.186.1/game.zip", "", nil) +func pof2(x int64) (out int64) { + out = 1 + org := x + for (x >> 1) > 0 { + out = out << 1 + x = x >> 1 + } + if org > out { + out = out << 1 + } + + return +} + +func TestDownload(t *testing.T) { + //download(".", "https://kdcc.action2quare.com/houston/_deploys/game/0.18.186.1/game.zip", "", nil) + fmt.Println(pof2(1023)) + fmt.Println(pof2(1024)) + fmt.Println(pof2(1025)) } diff --git a/server/operation.go b/server/operation.go index a697436..31c603e 100644 --- a/server/operation.go +++ b/server/operation.go @@ -7,7 +7,6 @@ import ( "strings" "sync" - "repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/houston/shared" "repositories.action2quare.com/ayo/houston/shared/protos" ) @@ -210,7 +209,6 @@ func (os *operationServer) ReportDeployingProgress(ctx context.Context, dp *prot os.db.Lock() defer os.db.Unlock() - logger.Println("ReportDeployingProgress :", dp.Hostname, dp.Name, dp.Version, dp.State, dp.Progress, dp.Total) for i, p := range os.db.progs { if p.Hostname == dp.Hostname && p.Name == dp.Name && p.Version == dp.Version { if dp.State == "done" {