Skip to content

Commit

Permalink
Merge pull request #1505 from 0chain/hotfix/wasm-memory
Browse files Browse the repository at this point in the history
Tune gc and set extra count to 0 for wasm
  • Loading branch information
dabasov authored May 23, 2024
2 parents e3f18c0 + 54c12bc commit 0f2c91d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ gosdk-build: gomod-download
go build -x -v -tags bn256 ./...

wasm-build: getrev
CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -buildvcs=false -o ./zcn.wasm ./wasmsdk
CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -ldflags="-s -w" -buildvcs=false -o ./zcn.wasm ./wasmsdk

wasm-test: wasm-build
env -i $(shell go env) PATH="$(shell go env GOROOT)/misc/wasm:$(PATH)" CGO_ENABLED=0 GOOS=js GOARCH=wasm go test -v github.com/0chain/gosdk/wasmsdk/jsbridge/...
Expand Down
3 changes: 3 additions & 0 deletions wasmsdk/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"errors"
"fmt"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -271,6 +272,8 @@ func main() {
}

hideLogs()
debug.SetGCPercent(40)
debug.SetMemoryLimit(2.5 * 1024 * 1024 * 1024) //2.5 GB

<-make(chan bool)

Expand Down
1 change: 1 addition & 0 deletions zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func SetMultiOpBatchSize(size int) {
func SetWasm() {
IsWasm = true
BatchSize = 5
extraCount = 0
}

func getPriceRange(name string) (PriceRange, error) {
Expand Down
9 changes: 6 additions & 3 deletions zboxcore/sdk/downloadworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import (
const (
DOWNLOAD_CONTENT_FULL = "full"
DOWNLOAD_CONTENT_THUMB = "thumbnail"
EXTRA_COUNT = 2
)

var (
extraCount = 2
)

type DownloadRequestOption func(dr *DownloadRequest)
Expand Down Expand Up @@ -531,7 +534,7 @@ func (req *DownloadRequest) processDownload() {
}
req.bufferMap = nil
}()
sz := downloadWorkerCount + EXTRA_COUNT
sz := downloadWorkerCount + extraCount
if sz > n {
sz = n
}
Expand Down Expand Up @@ -684,7 +687,7 @@ func (req *DownloadRequest) processDownload() {
firstReqWG := sync.WaitGroup{}
firstReqWG.Add(1)
eg, egCtx := errgroup.WithContext(ctx)
eg.SetLimit(downloadWorkerCount + EXTRA_COUNT)
eg.SetLimit(downloadWorkerCount + extraCount)
for i := 0; i < n; i++ {
j := i
if i == 1 {
Expand Down

0 comments on commit 0f2c91d

Please sign in to comment.