Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timings for upload #1476

Draft
wants to merge 18 commits into
base: sprint-1.14
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion core/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
//====== THIS IS AUTOGENERATED FILE. DO NOT MODIFY ========

package version
const VERSIONSTR = "v1.12.1-3-gbc68f654"
const VERSIONSTR = "v1.14.0-RC5-5-g0ec7e4ca"

30 changes: 26 additions & 4 deletions wasmsdk/blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,10 @@ func multiUpload(jsonBulkUploadOptions string) (MultiUploadResult, error) {
RemoteName: fileName,
RemotePath: fullRemotePath,
}
numBlocks := option.NumBlocks
if numBlocks <= 1 {
numBlocks = 100
}
numBlocks := 80
// if numBlocks <= 1 {
// numBlocks = 100
// }

options := []sdk.ChunkedUploadOption{
sdk.WithThumbnail(option.ThumbnailBytes.Buffer),
Expand Down Expand Up @@ -931,3 +931,25 @@ func getBlobbers(stakable bool) ([]*sdk.Blobber, error) {
}
return blobbs, err
}

type timingRes struct {
UploadTime int64 `json:"upload_time"`
TotalReadChunkTime int64 `json:"total_read_chunk_time"`
ReadTime int64 `json:"read_time"`
TotalTime int64 `json:"total_time"`
TotalBuildTime int64 `json:"total_build_time"`
TotalBlobberUpload int64 `json:"total_blobber_upload"`
}

func getUploadTiming() string {
res := timingRes{
UploadTime: sdk.TotalUploadTime,
TotalReadChunkTime: sdk.TotalReadChunkTime,
ReadTime: sdk.TotalReadTime,
TotalTime: sdk.TotalTime,
TotalBuildTime: sdk.TotalFormBuildTime,
TotalBlobberUpload: sdk.TotalUploadBlobberTime,
}
respBytes, _ := json.Marshal(res)
return string(respBytes)
}
28 changes: 20 additions & 8 deletions wasmsdk/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- for zcn.wasm-->
<script src="https://cdn.jsdelivr.net/gh/herumi/[email protected]/browser/bls.js"></script>
<script src="https://cdn.jsdelivr.net/gh/golang/[email protected]/misc/wasm/wasm_exec.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hash-wasm@4"></script>
<script src="zcn.js"></script>


Expand Down Expand Up @@ -171,10 +172,10 @@ <h2>please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates
}

const getWallet = () => {
const clientID = "b1d533fa60431a76014c4f94a7e8e19a3b1a7f34eebd4cacd29a8dd948b3844c"
const publicKey = "1f30a07b34146435cabc3244a1452fb8933f6982e0b33f384e5d25b9d6531e24e342003349990483f8481052a0748cbc72355d9cbda621ec914f7ed03c127791"
const privateKey = "fb98f46969be6921586e547b0f6f70c6b92d7823359f00bafa3900523910661a"
const mnemonic = "snake second property crush thrive monkey already lake fire sort cheap lake census adult this cloth panic filter taste punch pistol project rack obscure"
const clientID = "2ba00d37a162b3fe7783fd65c0507bca67418e9b2cac2a25244339f00ac30026"
const publicKey = "174cb917c5e5e5a7906b244bc73d03dc8adaf85a61d7c31989959ad1b4ffaa01884556b5e739f01bea08a329c14552e85540300484b24037962b730cca3dbd0c"
const privateKey = "8564a063420e98ee6826f56342b81a4ab3e5acab0b5bd5d9598b8c7207656415"
const mnemonic = "grunt human dog license demise black similar level satoshi hockey guide wrap drive chase lazy engage cruel fly unable verb point else minor where"
return {
clientID, publicKey, privateKey, mnemonic
}
Expand Down Expand Up @@ -211,7 +212,7 @@ <h2>please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates

let network = query.get('network')
if (!network || network == 'undefined') {
network = "dev.zus.network"
network = "demo.zus.network"
}

const blockWorker = 'https://' + network + '/dns';
Expand Down Expand Up @@ -441,13 +442,14 @@ <h2>please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates
alert("please selection allocationID")
return
}
const { list = [] } = await goWasm.sdk.listObjects(allocationId, '/')
const { list = [] } = await goWasm.sdk.listObjects(allocationId, '/',0,100)
files = list || []
bindFiles()
})

onClick('btnUploadFile', async () => {
const { files } = get('inputSelectedFile')
console.log("start upload")
if (files && files.length > 0) {

const objects = []
Expand All @@ -457,16 +459,26 @@ <h2>please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates
allocationId: allocationId,
remotePath: `/${file.name}`,
file: file,
thumbnailBytes: await readBytes(file),//only for demo, don't upload original file as thumbnail in production
encrypt: false,
webstreaming: false,
isUpdate: false,
isRepair: false,
numBlocks: 100,
numBlocks: 250,
callback: function (totalBytes, completedBytes, error) {
console.log(file.name + " " + completedBytes + "/" + totalBytes + " err:" + error)
}
})
{{/* const startChunkSize = 3 * 64 * 1024;
let endOffset = startChunkSize + 335413248;
//Time this for loop
const startTime = new Date().getTime();
for (let j = 0; j < endOffset; j += startChunkSize) {
console.log("readChunk",j)
const chunk = await readChunk(j, startChunkSize, file);
} */}}

{{/* const endTime = new Date().getTime();
console.log('Time taken: ', endTime - startTime); */}}
}
const results = await goWasm.bulkUpload(objects)
console.log(JSON.stringify(results))
Expand Down
Loading