From c9f0cd66b7757c92dbb74dafbc97bc18f190fff1 Mon Sep 17 00:00:00 2001 From: Alexey Kostin Date: Thu, 28 Feb 2019 13:44:50 +0300 Subject: [PATCH] fast object initialization --- ceph-gobench.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ceph-gobench.go b/ceph-gobench.go index 5ec5111..19fa916 100644 --- a/ceph-gobench.go +++ b/ceph-gobench.go @@ -13,7 +13,7 @@ import ( "time" ) -func bench(cephconn *Cephconnection, osddevice Device, buffs *[][]byte, startbuf *[]byte, params *Params, +func bench(cephconn *Cephconnection, osddevice Device, buffs *[][]byte, startbuff *[]byte, params *Params, wg *sync.WaitGroup, result chan string) { defer wg.Done() threadresult := make(chan []time.Duration, params.threadsCount) @@ -29,9 +29,12 @@ func bench(cephconn *Cephconnection, osddevice Device, buffs *[][]byte, startbuf name := "bench_" + strconv.Itoa(suffix) if osddevice.ID == GetObjActingPrimary(cephconn, *params, name) { objectnames = append(objectnames, name) - if err := cephconn.ioctx.WriteFull(name, *startbuf); err != nil { + if err := cephconn.ioctx.WriteFull(name, *startbuff); err != nil { log.Printf("Can't write object: %v, osd: %v", name, osddevice.Name) } + if err := cephconn.ioctx.Truncate(name, uint64(params.objectsize)); err != nil { + log.Printf("Can't truncate object: %v, osd: %v", name, osddevice.Name) + } } } for i := 0; i < int(params.threadsCount); i++ { @@ -209,7 +212,7 @@ func main() { for i := int64(0); i < 2*params.threadsCount; i++ { buffs = append(buffs, make([]byte, params.blocksize)) } - startbuff := make([]byte, params.objectsize) + startbuff := make([]byte, params.blocksize) for num := range buffs { _, err := rand.Read(buffs[num]) if err != nil {