chunksize 계산

This commit is contained in:
2023-10-24 20:57:41 +09:00
parent c9fecf55de
commit b8c1e97ab8
3 changed files with 41 additions and 7 deletions

View File

@ -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,
})

View File

@ -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))
}

View File

@ -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" {