Skip to content
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

How to tune connection? #327

Closed
siller174 opened this issue Aug 11, 2023 · 2 comments
Closed

How to tune connection? #327

siller174 opened this issue Aug 11, 2023 · 2 comments

Comments

@siller174
Copy link

siller174 commented Aug 11, 2023

Hello
I want to make a small benchmark of the cluster. The cluster in local and VM has same configuration.

If I bring up the cluster locally and run the following code:

package main

import (
	"context"
	"fmt"
	"reflect"
	"time"

	"github.com/tarantool/go-tarantool/v2"
	"github.com/tarantool/go-tarantool/v2/crud"
)

func main() {
	var (
		user = "admin"
		pass = "secret-cluster-cookie"
		dsn  = "localhost:3301"
	)
	
	connection, err := new(user, pass, dsn)
	if err != nil {
		panic(err)
	}

	benchInsert(connection, 1000)
}

func benchInsert(conn *tarantool.Connection, operations int) {
	ctx := context.Background()

	// Start benchmark
	startTime := time.Now()

	for i := 0; i < operations; i++ {
		insert := crud.MakeInsertObjectRequest("bench_space").
			Object(
				crud.MapObject(map[string]interface{}{
					"id":   i,
					"name": fmt.Sprintf("name %d", i),
				})).
			Context(ctx)

		tErr := crud.MakeResult(reflect.TypeOf(nil))

		err := conn.Do(insert).GetTyped(&tErr)
		if err != nil {
			panic(err)
		}
	}

	// Finish benchmark
	endTime := time.Now()

	// Calculate and print statistics
	totalOperations := operations
	totalTime := endTime.Sub(startTime).Seconds()
	throughput := float64(totalOperations) / totalTime

	fmt.Println("Insert benchmark results:")
	fmt.Println("------------------------")
	fmt.Printf("Total operations: %d\n", totalOperations)
	fmt.Printf("Total time: %.2f seconds\n", totalTime)
	fmt.Printf("Throughput: %.2f operations per second\n", throughput)
	fmt.Println("------------------------")
}


func new(user, pass, dsn string) (*tarantool.Connection, error) {
	conn, err := tarantool.Connect(dsn, tarantool.Opts{
		User: user,
		Pass: pass,
		//NoTLS: true,
	})
	if err != nil {
		return nil, fmt.Errorf("failed to connect tarantool: %w", err)
	}

	_, err = conn.Ping()
	if err != nil {
		return nil, fmt.Errorf("failed to ping tarantool: %w", err)
	}

	return conn, nil
}

I get the following results:

   Connect to localhost:3301
   Insert benchmark results:
   ------------------------
   Total operations: 1000
   Total time: 0.18 seconds
   Throughput: 5468.30 operations per second
   ------------------------

If I run this bench locally, but connect to remote cluster in VM, then I almost always have one rps (13 rps) for any operation.

   Connect to  10.61.140.1:3301
   Get benchmark results:
   ------------------------
   Total operations: 1000
   Total time: 80.45 seconds
   Throughput: 12.43 operations per second
   ------------------------

The question is what to change in order to increase throughput? What you should pay attention to? What you should tune?

@R-omk
Copy link

R-omk commented Aug 11, 2023

what to change in order to increase throughput?

Make requests in parallel ... it's all.

Your code just measures network latency, and has nothing to do with a benchmark.

@oleg-jukovec
Copy link
Collaborator

oleg-jukovec commented Aug 11, 2023

You could encode/prepare to send a request in parallel:

conn.Do(request)

and wait for a response/decode responses in parallel:

future.GetTyped(&resp)

Depending on the size of requests/responses you will need a different number of goroutines/threads for Do() and GetTyped(). You сan start with number of cores of your CPU for both.

See also 'Concurrency` option and that.
https://pkg.go.dev/github.com/tarantool/go-tarantool#Opts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants