FAQ
hi Ugorji

if I increase i loop 0 to 400.. or more, MsgPack or Gob takes too long to
decode same message ( for i:=0 200 usec, if i=100 loop few in 200 usec few
takes 6 millisec )

Please help

func main() {
     t1:=time.Now()
     wg := &sync.WaitGroup{}
     wg.Add(400)

     for i:=0;i<400;i++ {
         go invoke(wg, time.Now(), i, encodeddata)
     }

     wg.Wait()

     fmt.Printf("Total Time - %s\n", time.Since(t1))
}

func invoke(wg *sync.WaitGroup, t time.Time, i int, dat []byte){
     fmt.Printf("%s > %s > %s\n", i, t, time.Now())
     DecodeMsgPack(dat)
     wg.Done()
}

func DecodeMsgPack(b []byte) {

     var mh1 codec.MsgpackHandle
     mh1.MapType = reflect.TypeOf(map[string]interface{}(nil))

     dec := codec.NewDecoderBytes(b, &mh1)
     c := new(Ux.MyStructl)
     dec.Decode(&c)

     //return c
}



On Wednesday, April 11, 2012 at 11:01:01 PM UTC+5:30, Ugorji Nwoke wrote:

Announcing go-msgpack, a rich Go library for encoding/decoding to msgpack
binary format, with support for net/rpc communication.

https://github.com/ugorji/go-msgpack
http://gopkgdoc.appspot.com/pkg/github.com/ugorji/go-msgpack/msgpack

It provides features similar to encoding packages in the standard library
(ie json, xml, gob, etc).

*Supports:*
- Standard Marshal/Unmarshal interface.
- Standard field renaming via tags
- Encoding from any value (struct, slice, map, primitives, pointers,
interface{}, etc)
- Decoding into a pointer to any non-nil value (struct, slice, map, int,
float32, bool, string, etc)
- Decoding into a nil interface{} (big)
- Handles time.Time transparently (using RFC3339 format).

*Usage*
// v can be interface{}, int32, bool, map[string]bool, etc
dec = msgpack.NewDecoder(r)
err = dec.Decode(&v)

enc = msgpack.NewEncoder(w)
err = enc.Encode(v)

//methods below are convenience methods over functions above.
data, err = msgpack.Marshal(v)
err = msgpack.Unmarshal(data, &v)

//RPC Communication
conn, err = net.Dial("tcp", "localhost:5555")
rpcCodec := msgpack.NewRPCCodec(conn)
client := rpc.NewClientWithCodec(rpcCodec)
...

*Why?*
I was initially looking at different binary serialization formats for an
application I'm developing. I looked at Thrift, Protocol Buffers, BSON,
Msgpack, etc.

I finally decided on msgpack:
- compact
- supports basic types (just like JSON. Numbers, Bool, Null, Bytes/String,
Map, List) from which other data structures else can be assembled
- raw bytes support (which can represent binary data or strings)
- no schema needed (just like JSON)
- cross-language support
- has pretty good mindshare

Unfortunately, the Go library on the msgpack.org site is old, does not
build, and is not "smart" like the encoding/json package. Specifically, it
doesn't allow me decode into a typed object (e.g. struct, bool, etc).

I wrote go-msgpack to give the same conveniences we've gotten used to
(spoiled by using the encoding/json package), while being really
performant.

*Summary of my testing:*
- Decodes significantly faster (120% faster) and encodes only slightly
slower (20% slower) than encoding/json
- Uses less disk space (40% less)
- May not require compression (compression only gave a 10% reduction in
size).
Since compression/decompression time may be significant, this may be
an important win.

Hope folks use it and enjoy using it. I know I will. Please feel free to
send me feedback.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Dave Cheney at Nov 23, 2015 at 8:03 am
    Please see my reply to your duplicate post.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 23, '15 at 7:51a
activeNov 23, '15 at 8:03a
posts2
users2
websitegolang.org

2 users in discussion

Desaiabhijit: 1 post Dave Cheney: 1 post

People

Translate

site design / logo © 2021 Grokbase