nebulagraph

package module
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2022 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

xk6-nebula

This is a k6 extension using the xk6 system.

Used to test Nebula-Graph.

Dependency

  • k6 v0.33.0
  • xk6 v0.4.1
  • Golang 1.16+

Version match

There are the version correspondence between k6-plugin and Nebula:

k6-plugin Version Nebula Version
v0.0.8 2.5.0, 2.5.1, 2.6.0, 2.6.1
v0.0.9 3.0.0
master nightly

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Download xk6:
go install github.com/k6io/xk6/cmd/xk6@v0.4.1
  1. Build the binary:
xk6 build --with github.com/vesoft-inc/k6-plugin@{version}
# e.g. build v0.0.8
xk6 build --with github.com/vesoft-inc/k6-plugin@v0.0.8
# e.g. build master
xk6 build --with github.com/vesoft-inc/k6-plugin@master

Example

import nebulaPool from 'k6/x/nebulagraph';
import { check } from 'k6';
import { Trend } from 'k6/metrics';
import { sleep } from 'k6';

var lantencyTrend = new Trend('latency');
var responseTrend = new Trend('responseTime');
// initial nebula connect pool
// by default the channel buffer size is 20000, you can reset it with
// var pool = nebulaPool.initWithSize("192.168.8.152:9669", {poolSize}, {bufferSize}); e.g.
// var pool = nebulaPool.initWithSize("192.168.8.152:9669", 1000, 4000)
var pool = nebulaPool.init("192.168.8.152:9669", 400);

// initial session for every vu
var session = pool.getSession("root", "nebula")
session.execute("USE sf1")


export function setup() {
  // config csv file
  pool.configCSV("person.csv", "|", false)
  // config output file, save every query information
  pool.configOutput("output.csv")
  sleep(1)
}

export default function (data) {
  // get csv data from csv file
  let d = session.getData()
  // d[0] means the first column data in the csv file
  let ngql = 'go 2 steps from ' + d[0] + ' over KNOWS '
  let response = session.execute(ngql)
  check(response, {
    "IsSucceed": (r) => r.isSucceed() === true
  });
  // add trend
lantencyTrend.add(response.getLatency());
responseTrend.add(response.getResponseTime());
};

export function teardown() {
  pool.close()
}

Result

# -u means how many virtual users, i.e the concurrent users
# -d means the duration that test running, e.g. `3s` means 3 seconds, `5m` means 5 minutes.
>./k6 run nebula-test.js -u 3 -d 3s                                                      

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

INFO[0000] 2021/07/07 16:50:25 [INFO] begin init the nebula pool
INFO[0000] 2021/07/07 16:50:25 [INFO] connection pool is initialized successfully
INFO[0000] 2021/07/07 16:50:25 [INFO] finish init the pool
  execution: local
     script: nebula-test.js
     output: -

  scenarios: (100.00%) 1 scenario, 3 max VUs, 33s max duration (incl. graceful stop):
           * default: 3 looping VUs for 3s (gracefulStop: 30s)

INFO[0004] 2021/07/07 16:50:29 [INFO] begin close the nebula pool

running (04.1s), 0/3 VUs, 570 complete and 0 interrupted iterations
default ✓ [======================================] 3 VUs  3s
INFO[0004] 2021/07/07 16:50:29 [INFO] begin init the nebula pool
INFO[0004] 2021/07/07 16:50:29 [INFO] connection pool is initialized successfully
INFO[0004] 2021/07/07 16:50:29 [INFO] finish init the pool

     ✓ IsSucceed

     █ setup

     █ teardown

     checks...............: 100.00% ✓ 570        ✗ 0
     data_received........: 0 B     0 B/s
     data_sent............: 0 B     0 B/s
     iteration_duration...: avg=17.5ms       min=356.6µs med=11.44ms max=1s     p(90)=29.35ms p(95)=38.73ms
     iterations...........: 570     139.877575/s
     latency..............: avg=2986.831579  min=995     med=2663    max=18347  p(90)=4518.4  p(95)=5803
     responseTime.........: avg=15670.263158 min=4144    med=11326.5 max=108286 p(90)=28928.9 p(95)=38367.1
     vus..................: 3       min=0        max=3
     vus_max..............: 3       min=3        max=3
  • checks, one check per iteration, verify isSucceed by default.
  • data_received and data_sent, used by HTTP requests, useless for nebula.
  • iteration_duration, time consuming for every iteration.
  • latency, time consuming in nebula server.
  • responseTime, time consuming in client.
  • vus, concurrent virtual users.

In general

iteration_duration = responseTime + (time consuming for read data from csv)

responseTime = latency + (time consuming for network) + (client decode)

The output.csv saves data as below:

>head output.csv                                                                          

timestamp,nGQL,latency,responseTime,isSucceed,rows,errorMsg
1625647825,USE sf1,7808,10775,true,0,
1625647825,USE sf1,4055,7725,true,0,
1625647825,USE sf1,3431,10231,true,0,
1625647825,USE sf1,2938,5600,true,0,
1625647825,USE sf1,2917,5410,true,0,
1625647826,go 2 steps from 933 over KNOWS ,6022,24537,true,1680,
1625647826,go 2 steps from 1129 over KNOWS ,6141,25861,true,1945,
1625647826,go 2 steps from 4194 over KNOWS ,6317,26309,true,1581,
1625647826,go 2 steps from 8698 over KNOWS ,4388,22597,true,1530,

Advanced usage

By default, all vus use the same channel to read the csv data.

You can change the strategy before getSession function.

As each vu uses a separate channel, you can reduce channel buffer size to save memory.

// initial nebula connect pool, channel buffer size is 4000
var pool = nebulaPool.initWithSize("192.168.8.61:9669", 400, 4000);

// set csv strategy, 1 means each vu has a separate csv reader.
pool.configCsvStrategy(1)

// initial session for every vu
var session = pool.getSession("root", "nebula")

Please refer to nebula-test-insert.js for more details.

Batch insert

It can also use k6 for batch insert testing.

# create schema
cd example
nebula-console -addr 192.168.8.61 -port 9669 -u root -p nebula -f schema.ngql

# run testing
../k6 run nebula-test-insert.js -vu 10 -d 30s 

# by default, the batch size is 100, you can change it in `nebula-test-insert.js`
sed -i 's/let batchSize.*/let batchSize = 300/g' nebula-test-insert.js
../k6 run nebula-test-insert.js -vu 10 -d 30s 

Test stages

It can specify the target number of VUs by k6 stages in options. e.g.

import nebulaPool from 'k6/x/nebulagraph';
import { check } from 'k6';
import { Trend } from 'k6/metrics';
import { sleep } from 'k6';

export let options = {
  stages: [
    { duration: '3m', target: 10 },
    { duration: '5m', target: 10 },
    { duration: '10m', target: 35 },
    { duration: '3m', target: 0 },
  ],
};

var lantencyTrend = new Trend('latency');
var responseTrend = new Trend('responseTime');

The options means ramping up from 1 to 10 vus in 3 minutes, then runnign test with 10 vus in 5 minutes.

And then ramping up from 10 vus to 35 vus in 10 minutes.

Then ramping down from 35 vu3 to 0 in 3 minutes.

It is much useful when we test multiple scenarios.

please refer to k6 options

Documentation

Index

Constants

View Source
const (
	// AllInOne all the vus use the same DataCh
	AllInOne csvReaderStrategy = iota
	// Separate each vu has a seprate DataCh
	Separate
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVReader

type CSVReader struct {
	Path       string
	Delimiter  string
	WithHeader bool
	DataCh     chan<- Data
}

func NewCsvReader

func NewCsvReader(path, delimiter string, withHeader bool, dataCh chan<- Data) *CSVReader

func (*CSVReader) ReadForever

func (c *CSVReader) ReadForever() error

type CSVWriter

type CSVWriter struct {
	Path      string
	Header    []string
	Delimiter string
	DataCh    <-chan []string
}

func NewCsvWriter

func NewCsvWriter(path, delimiter string, header []string, dataCh <-chan []string) *CSVWriter

func (*CSVWriter) WriteForever

func (c *CSVWriter) WriteForever() error

type Data

type Data []string

Data data in csv file

type NebulaPool

type NebulaPool struct {
	HostList []nebula.HostAddress
	Pool     *nebula.ConnectionPool
	Log      nebula.Logger
	DataChs  []chan Data
	OutoptCh chan []string
	// contains filtered or unexported fields
}

NebulaPool nebula connection pool

func New

func New() *NebulaPool

New for k6 initialization.

func (*NebulaPool) Close

func (np *NebulaPool) Close() error

Close close the nebula pool

func (*NebulaPool) ConfigCSV

func (np *NebulaPool) ConfigCSV(path, delimiter string, withHeader bool) error

ConfigCSV config the csv file to be read

func (*NebulaPool) ConfigCsvStrategy

func (np *NebulaPool) ConfigCsvStrategy(strategy int)

ConfigCsvStrategy set csv reader strategy

func (*NebulaPool) ConfigOutput

func (np *NebulaPool) ConfigOutput(path string) error

ConfigOutput config the output file, would write the execution outputs

func (*NebulaPool) GetSession

func (np *NebulaPool) GetSession(user, password string) (*NebulaSession, error)

GetSession get the session from pool

func (*NebulaPool) Init

func (np *NebulaPool) Init(address string, concurrent int) (*NebulaPool, error)

Init init nebula pool with address and concurrent, by default the buffersize is 20000

func (*NebulaPool) InitWithSize

func (np *NebulaPool) InitWithSize(address string, concurrent int, size int) (*NebulaPool, error)

InitWithSize init nebula pool with channel buffer size

func (*NebulaPool) NewSSLConfig added in v0.0.9

func (np *NebulaPool) NewSSLConfig(rootCAPath, certPath, privateKeyPath string)

NewSSLConfig return sslConfig

type NebulaSession

type NebulaSession struct {
	Session *nebula.Session
	Pool    *NebulaPool
	DataCh  chan Data
}

NebulaSession a wrapper for nebula session, could read data from DataCh

func (*NebulaSession) Execute

func (s *NebulaSession) Execute(stmt string) (*Response, error)

Execute execute nebula query

func (*NebulaSession) GetData

func (s *NebulaSession) GetData() (Data, error)

GetData get data from csv reader

type Response

type Response struct {
	*nebula.ResultSet
	ResponseTime int32
}

Response a wrapper for nebula resultset

func (*Response) GetResponseTime

func (r *Response) GetResponseTime() int32

GetResponseTime GetResponseTime

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL