Skip to content

Add WriterPool for compress #19

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ package main

import (
"fmt"
"github.com/pai-eas/eas-golang-sdk/eas"
"github.com/xd-luqiang/eas-golang-sdk/eas"
)

func main() {
Expand Down Expand Up @@ -68,7 +68,7 @@ package main

import (
"fmt"
"github.com/pai-eas/eas-golang-sdk/eas"
"github.com/xd-luqiang/eas-golang-sdk/eas"
)

func main() {
Expand Down Expand Up @@ -101,7 +101,7 @@ package main

import (
"fmt"
"github.com/pai-eas/eas-golang-sdk/eas"
"github.com/xd-luqiang/eas-golang-sdk/eas"
)

func main() {
Expand Down Expand Up @@ -132,7 +132,7 @@ package main

import (
"fmt"
"github.com/pai-eas/eas-golang-sdk/eas"
"github.com/xd-luqiang/eas-golang-sdk/eas"
)

func main() {
Expand Down Expand Up @@ -161,7 +161,7 @@ package main

import (
"fmt"
"github.com/pai-eas/eas-golang-sdk/eas"
"github.com/xd-luqiang/eas-golang-sdk/eas"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion eas/queue_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/pai-eas/eas-golang-sdk/eas/types"
"github.com/xd-luqiang/eas-golang-sdk/eas/types"
"golang.org/x/net/websocket"
)

Expand Down
2 changes: 1 addition & 1 deletion eas/queue_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/pai-eas/eas-golang-sdk/eas/types"
"github.com/xd-luqiang/eas-golang-sdk/eas/types"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion eas/tf_data_type.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eas

import (
"github.com/pai-eas/eas-golang-sdk/eas/types/tf_predict_protos"
"github.com/xd-luqiang/eas-golang-sdk/eas/types/tf_predict_protos"
)

// type tf_predict_protos.ArrayDataType tf_predict_protos.ArrayDataType
Expand Down
2 changes: 1 addition & 1 deletion eas/tf_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package eas

import (
"github.com/golang/protobuf/proto"
"github.com/pai-eas/eas-golang-sdk/eas/types/tf_predict_protos"
"github.com/xd-luqiang/eas-golang-sdk/eas/types/tf_predict_protos"
)

// TFRequest class for tensorflow data and requests
Expand Down
2 changes: 1 addition & 1 deletion eas/torch_data_type.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eas

import (
"github.com/pai-eas/eas-golang-sdk/eas/types/torch_predict_protos"
"github.com/xd-luqiang/eas-golang-sdk/eas/types/torch_predict_protos"
)

// type torch_predict_protos.ArrayDataType torch_predict_protos.ArrayDataType
Expand Down
2 changes: 1 addition & 1 deletion eas/torch_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package eas

import (
"github.com/golang/protobuf/proto"
"github.com/pai-eas/eas-golang-sdk/eas/types/torch_predict_protos"
"github.com/xd-luqiang/eas-golang-sdk/eas/types/torch_predict_protos"
)

// TorchRequest class for PyTorch data and requests
Expand Down
10 changes: 5 additions & 5 deletions eas/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/json"
"io"

"github.com/pai-eas/eas-golang-sdk/eas/types/queue_service_protos"
"github.com/xd-luqiang/eas-golang-sdk/eas/types/queue_service_protos"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -243,10 +243,10 @@ type lengthDelimitedFrameReader struct {
//
// The protocol is:
//
// stream: message ...
// message: prefix body
// prefix: 4 byte uint32 in BigEndian order, denotes length of body
// body: bytes (0..prefix)
// stream: message ...
// message: prefix body
// prefix: 4 byte uint32 in BigEndian order, denotes length of body
// body: bytes (0..prefix)
//
// If the buffer passed to Read is not long enough to contain an entire frame, io.ErrShortRead
// will be returned along with the number of bytes read.
Expand Down
31 changes: 28 additions & 3 deletions eas/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,27 @@ import (
"encoding/hex"
"fmt"
"io"
"sync"
)

var gzipWriterPool = &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(nil)
},
}

var zlibWriterPool = &sync.Pool{
New: func() interface{} {
return zlib.NewWriter(nil)
},
}

type CompressWriter interface {
Reset(io.Writer)
Write([]byte) (int, error)
Close() error
}

func md5sum(data []byte) string {
h := md5.New()
h.Write(data)
Expand All @@ -27,13 +46,19 @@ func hmacSha256(data string, secret string) string {

func compress(data []byte, compressType string) ([]byte, error) {
var b bytes.Buffer
var w io.WriteCloser
var w CompressWriter

switch compressType {
case CompressTypeGzip:
w = gzip.NewWriter(&b)
// w = gzip.NewWriter(&b)
w = gzipWriterPool.Get().(*gzip.Writer)
defer gzipWriterPool.Put(w)
w.Reset(&b)
case CompressTypeZlib:
w = zlib.NewWriter(&b)
// w = zlib.NewWriter(&b)
w = zlibWriterPool.Get().(*zlib.Writer)
defer zlibWriterPool.Put(w)
w.Reset(&b)
default:
return nil, fmt.Errorf("unsupported compression type: %s", compressType)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/pai-eas/eas-golang-sdk
module github.com/xd-luqiang/eas-golang-sdk

go 1.14

Expand Down