Browse Source

修改EC配置用于测试

gitlink
JeshuaRen 1 year ago
parent
commit
9688e918dd
3 changed files with 200 additions and 1 deletions
  1. +95
    -0
      main.go
  2. +1
    -1
      sdks/storage/models.go
  3. +104
    -0
      utils/time2/test.go

+ 95
- 0
main.go View File

@@ -0,0 +1,95 @@
package main

import (
"fmt"
"io"
"os"
"strconv"
"time"

cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
)

func main() {
test1("http://121.36.5.116:32010")
// test2("http://127.0.0.1:7890")
}

func test1(url string) {
cli := cdssdk.NewClient(&cdssdk.Config{
URL: url,
})

openLen, err := strconv.ParseInt(os.Args[1], 10, 64)
if err != nil {
fmt.Println(err)
return
}

readLen, err := strconv.ParseInt(os.Args[2], 10, 64)
if err != nil {
fmt.Println(err)
return
}

partLen, err := strconv.ParseInt(os.Args[3], 10, 64)
if err != nil {
fmt.Println(err)
return
}

startTime := time.Now()
obj, err := cli.Object().Download(cdssdk.ObjectDownload{
UserID: 1,
ObjectID: 470790,
Offset: 0,
Length: &openLen,
PartSize: partLen,
})
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Open time: %v\n", time.Since(startTime))

startTime = time.Now()
buf := make([]byte, readLen)
_, err = io.ReadFull(obj.File, buf)
fmt.Printf("Read time: %v\n", time.Since(startTime))
if err != nil {
fmt.Println(err)
return
}

startTime = time.Now()
obj.File.Close()
fmt.Printf("Close time: %v\n", time.Since(startTime))
}

func test2(url string) {
cli := cdssdk.NewClient(&cdssdk.Config{
URL: url,
})

obj, err := cli.Object().Download(cdssdk.ObjectDownload{
UserID: 1,
ObjectID: 27151,
Offset: 0,
PartSize: 100000000,
// Length: &openLen,
})

if err != nil {
fmt.Println(err)
return
}

f, err := os.Create("test.txt")
if err != nil {
fmt.Println(err)
return
}

io.Copy(f, obj.File)
}


+ 1
- 1
sdks/storage/models.go View File

@@ -71,7 +71,7 @@ func (b *RepRedundancy) Value() (driver.Value, error) {
return serder.ObjectToJSONEx[Redundancy](b)
}

var DefaultECRedundancy = *NewECRedundancy(2, 3, 1024*1024*5)
var DefaultECRedundancy = *NewECRedundancy(3, 6, 1024*1024*5)

type ECRedundancy struct {
serder.Metadata `union:"ec"`


+ 104
- 0
utils/time2/test.go View File

@@ -0,0 +1,104 @@
package time2

import (
"fmt"
"path"
"runtime"
"strings"
"time"
)

type Measurement struct {
startTime time.Time
lastPointTime time.Time
printer func(string)
on bool
title string
}

func NewMeasurement(printer func(string)) Measurement {
return Measurement{
printer: printer,
}
}

func (m *Measurement) Begin(on bool, title ...string) {
if m == nil {
return
}

m.on = on
m.title = strings.Join(title, ".")

if on {
m.startTime = time.Now()
m.lastPointTime = m.startTime

_, file, line, ok := runtime.Caller(1)

titlePart := ""
if m.title != "" {
titlePart = fmt.Sprintf(":%s", m.title)
}

if ok {
m.printer(fmt.Sprintf("[begin%v]%v:%v", titlePart, path.Base(file), line))
} else {
m.printer(fmt.Sprintf("[begin%v]unknown point", titlePart))
}
}
}

func (m *Measurement) Point(head ...string) {
if m == nil {
return
}

if m.on {
m.printer(m.makePointString(strings.Join(head, ".")))
}
}

func (m *Measurement) makePointString(head string) string {
last := m.lastPointTime
now := time.Now()
m.lastPointTime = now

_, file, line, ok := runtime.Caller(2)

prefixCont := ""

if m.title != "" {
prefixCont = m.title
}

if head != "" {
if prefixCont == "" {
prefixCont = head
} else {
prefixCont = fmt.Sprintf("%s.%s", prefixCont, head)
}
}

prefixPart := ""
if prefixCont != "" {
prefixPart = fmt.Sprintf("[%s]", prefixCont)
}

if ok {
return fmt.Sprintf("%v%v:%v@%v(%v)", prefixPart, path.Base(file), line, now.Sub(last), now.Sub(m.startTime))
}

return fmt.Sprintf("%vunknown point@%v(%v)", prefixPart, now.Sub(last), now.Sub(m.startTime))
}

func (m *Measurement) End(head ...string) {
if m == nil {
return
}

if m.on {
m.printer(fmt.Sprintf("[end]%v\n", m.makePointString(strings.Join(head, "."))))
}
}


Loading…
Cancel
Save