[Groonga-commit] groonga/grnci at 0a84e8c [master] Add an argument to NewGQTPClient to set the max. number of idle connections.

アーカイブの一覧に戻る

Susumu Yata null+****@clear*****
Thu Jul 27 11:07:41 JST 2017


Susumu Yata	2017-07-27 11:07:41 +0900 (Thu, 27 Jul 2017)

  New Revision: 0a84e8c1ffd51b4f9a688ab63914ecbaec4f49ad
  https://github.com/groonga/grnci/commit/0a84e8c1ffd51b4f9a688ab63914ecbaec4f49ad

  Message:
    Add an argument to NewGQTPClient to set the max. number of idle connections.

  Modified files:
    v2/gqtp.go

  Modified: v2/gqtp.go (+20 -5)
===================================================================
--- v2/gqtp.go    2017-07-27 10:49:49 +0900 (da12b40)
+++ v2/gqtp.go    2017-07-27 11:07:41 +0900 (f967e72)
@@ -28,9 +28,9 @@ const (
 )
 
 const (
-	gqtpMaxChunkSize      = 1 << 30 // Maximum chunk size
-	gqtpDefaultBufferSize = 1 << 16 // Default buffer size
-	gqtpMaxIdleConns      = 2       // Maximum number of idle connections
+	gqtpMaxChunkSize        = 1 << 30 // Maximum chunk size
+	gqtpDefaultBufferSize   = 1 << 16 // Default buffer size
+	gqtpDefaultMaxIdleConns = 2       // Default maximum number of idle connections
 )
 
 // gqtpHeader is a GQTP header.
@@ -394,6 +394,18 @@ func (c *GQTPConn) Query(cmd *Command) (Response, error) {
 	return c.exec(cmd.String(), cmd.Body())
 }
 
+// GQTPClientOptions is options of GQTPClient.
+type GQTPClientOptions struct {
+	MaxIdleConns int // Maximum number of idle connections
+}
+
+// NewGQTPClientOptions returns the default GQTPClientOptions.
+func NewGQTPClientOptions() *GQTPClientOptions {
+	return &GQTPClientOptions{
+		MaxIdleConns: gqtpDefaultMaxIdleConns,
+	}
+}
+
 // GQTPClient is a thread-safe GQTP client.
 type GQTPClient struct {
 	addr      string
@@ -402,14 +414,17 @@ type GQTPClient struct {
 
 // NewGQTPClient returns a new GQTPClient connected to a GQTP server.
 // The expected address format is [scheme://][host][:port].
-func NewGQTPClient(addr string) (*GQTPClient, error) {
+func NewGQTPClient(addr string, options *GQTPClientOptions) (*GQTPClient, error) {
+	if options == nil {
+		options = NewGQTPClientOptions()
+	}
 	conn, err := DialGQTP(addr)
 	if err != nil {
 		return nil, err
 	}
 	c := &GQTPClient{
 		addr:      addr,
-		idleConns: make(chan *GQTPConn, gqtpMaxIdleConns),
+		idleConns: make(chan *GQTPConn, options.MaxIdleConns),
 	}
 	c.idleConns <- conn
 	conn.client = c
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る