mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Benchmark implementations can now use 'HasClient' as a component which provides an Init method which sets up the pilosa client in a configurable way. Implementations must still expose the ClientType argument through ConsumeFlags and describe it in Usage()
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package bench
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/umbel/pilosa"
|
|
)
|
|
|
|
func firstHostClient(hosts []string) (*pilosa.Client, error) {
|
|
cli, err := pilosa.NewClient(hosts[0])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return cli, nil
|
|
}
|
|
|
|
func roundRobinClient(hosts []string, agentNum int) (*pilosa.Client, error) {
|
|
cliNum := agentNum % len(hosts)
|
|
return firstHostClient(hosts[cliNum:])
|
|
}
|
|
|
|
// HasClient provides a reusable component for Benchmark implementations which
|
|
// provides the Init method, a ClientType argument and a cli internal variable.
|
|
type HasClient struct {
|
|
cli *pilosa.Client
|
|
ClientType string
|
|
}
|
|
|
|
// Init for HasClient looks at the ClientType field and creates a pilosa client
|
|
// either using the first host in the list of hosts or based on the agent
|
|
// number mod len(hosts)
|
|
func (h *HasClient) Init(hosts []string, agentNum int) error {
|
|
var err error
|
|
switch h.ClientType {
|
|
case "single":
|
|
h.cli, err = firstHostClient(hosts)
|
|
return err
|
|
case "round_robin":
|
|
h.cli, err = roundRobinClient(hosts, agentNum)
|
|
return err
|
|
default:
|
|
return fmt.Errorf("Unsupported ClientType: %v", h.ClientType)
|
|
}
|
|
}
|