chunksize 계산
This commit is contained in:
@ -23,6 +23,24 @@ import (
|
|||||||
"golang.org/x/text/transform"
|
"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) {
|
func download(dir string, urlpath string, accessToken string, cb func(int64, int64)) (target string, err error) {
|
||||||
logger.Println("start downloading", dir, urlpath)
|
logger.Println("start downloading", dir, urlpath)
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -59,13 +77,13 @@ func download(dir string, urlpath string, accessToken string, cb func(int64, int
|
|||||||
cl := resp.Header.Get("Content-Length")
|
cl := resp.Header.Get("Content-Length")
|
||||||
totalLength, _ := strconv.ParseInt(cl, 10, 0)
|
totalLength, _ := strconv.ParseInt(cl, 10, 0)
|
||||||
totalWritten := int64(0)
|
totalWritten := int64(0)
|
||||||
|
chunkSize := pof2(totalLength/100, 1024*1024)
|
||||||
if cb != nil {
|
if cb != nil {
|
||||||
cb(0, totalLength)
|
cb(0, totalLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
written, err := io.CopyN(out, resp.Body, 1024*1024)
|
written, err := io.CopyN(out, resp.Body, chunkSize)
|
||||||
totalWritten += written
|
totalWritten += written
|
||||||
if cb != nil {
|
if cb != nil {
|
||||||
cb(totalWritten, totalLength)
|
cb(totalWritten, totalLength)
|
||||||
@ -324,7 +342,7 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.Deplo
|
|||||||
}
|
}
|
||||||
|
|
||||||
cb(&protos.DeployingProgress{
|
cb(&protos.DeployingProgress{
|
||||||
State: "unzip/untar",
|
State: "unpack",
|
||||||
Progress: 0,
|
Progress: 0,
|
||||||
Total: 0,
|
Total: 0,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,9 +1,27 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDownload(t *testing.T) {
|
func pof2(x int64) (out int64) {
|
||||||
download(".", "https://kdcc.action2quare.com/houston/_deploys/game/0.18.186.1/game.zip", "", nil)
|
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))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
|
||||||
"repositories.action2quare.com/ayo/houston/shared"
|
"repositories.action2quare.com/ayo/houston/shared"
|
||||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||||
)
|
)
|
||||||
@ -210,7 +209,6 @@ func (os *operationServer) ReportDeployingProgress(ctx context.Context, dp *prot
|
|||||||
os.db.Lock()
|
os.db.Lock()
|
||||||
defer os.db.Unlock()
|
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 {
|
for i, p := range os.db.progs {
|
||||||
if p.Hostname == dp.Hostname && p.Name == dp.Name && p.Version == dp.Version {
|
if p.Hostname == dp.Hostname && p.Name == dp.Name && p.Version == dp.Version {
|
||||||
if dp.State == "done" {
|
if dp.State == "done" {
|
||||||
|
|||||||
Reference in New Issue
Block a user