forked from tarantool/cartridge-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bench: add the ability to set a load profile
Patch for load profile with additional select and update operations and with support for benchmark space pre-filling. Added: - Flag "insert" - percentage of insert operations to bench space. - Flag "select" - percentage of select operations from bench space. - Flag "update" - percentage of update operations in bench space. - Flag "fill" - number of records to pre-fill the space. ``` user@cartridge-cli % ./cartridge bench --select=30 --update=30 --insert=40 --fill=100000 Tarantool 2.8.3 (Binary) f4897ffe-98dd-40fc-a6f2-21ca8bb52fe7 Parameters: URL: 127.0.0.1:3301 user: guest connections: 10 simultaneous requests: 10 duration: 10 seconds key size: 10 bytes data size: 20 bytes insert: 40 percentages select: 30 percentages update: 30 percentages Data schema | key | value | ------------------------------ | ------------------------------ | random(10) | random(20) The pre-filling of the space has started, because the insert operation is not specified or there was an explicit instruction for pre-filling. ... Pre-filling is finished. Number of records: 100000 Benchmark start. ... Benchmark stop. Results: Success operations: 1332979 Failed operations: 0 Request count: 1334004 Time (seconds): 10.000733 Requests per second: 133390 ``` Part of tarantool#645
- Loading branch information
1 parent
0a1d653
commit f2dd922
Showing
9 changed files
with
312 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package bench | ||
|
||
import ( | ||
"math/rand" | ||
"reflect" | ||
|
||
"github.com/FZambia/tarantool" | ||
"github.com/tarantool/cartridge-cli/cli/common" | ||
) | ||
|
||
// insertOperation execute insert operation. | ||
func insertOperation(request Request) { | ||
_, err := request.tarantoolConnection.Exec( | ||
tarantool.Insert( | ||
benchSpaceName, | ||
[]interface{}{ | ||
common.RandomString(request.ctx.KeySize), | ||
common.RandomString(request.ctx.DataSize), | ||
})) | ||
request.results.incrementRequestsCounters(err) | ||
} | ||
|
||
// selectOperation execute select operation. | ||
func selectOperation(request Request) { | ||
_, err := request.tarantoolConnection.Exec(tarantool.Call( | ||
*request.getRandomTupleCommand, | ||
[]interface{}{rand.Int()})) | ||
request.results.incrementRequestsCounters(err) | ||
} | ||
|
||
// updateOperation execute update operation. | ||
func updateOperation(request Request) { | ||
getRandomTupleResponse, err := request.tarantoolConnection.Exec( | ||
tarantool.Call(*request.getRandomTupleCommand, | ||
[]interface{}{rand.Int()})) | ||
if err == nil { | ||
data := getRandomTupleResponse.Data | ||
if len(data) > 0 { | ||
key := reflect.ValueOf(data[0]).Index(0).Elem().String() | ||
_, err := request.tarantoolConnection.Exec( | ||
tarantool.Update( | ||
benchSpaceName, | ||
benchSpacePrimaryIndexName, | ||
[]interface{}{key}, | ||
[]tarantool.Op{tarantool.Op( | ||
tarantool.OpAssign( | ||
2, | ||
common.RandomString(request.ctx.DataSize)))})) | ||
request.results.incrementRequestsCounters(err) | ||
} | ||
} | ||
} | ||
|
||
// getNext return next operation in operations sequence. | ||
func (requestsSequence *RequestsSequence) getNext() Request { | ||
// If at the moment the number of remaining requests = 0, | ||
// then find a new generator, which requests count > 0. | ||
// If new generator has requests count = 0, then repeat. | ||
requestsSequence.findNewRequestsGeneratorMutex.Lock() | ||
for requestsSequence.currentCounter == 0 { | ||
// Increase the index, which means logical switching to a new generator. | ||
requestsSequence.currentRequestIndex++ | ||
requestsSequence.currentRequestIndex %= len(requestsSequence.requests) | ||
// Get new generator by index. | ||
nextRequestsGenerator := requestsSequence.requests[requestsSequence.currentRequestIndex] | ||
// Get requests count for new operation. | ||
requestsSequence.currentCounter = nextRequestsGenerator.count | ||
} | ||
// Logical taking of a single request. | ||
requestsSequence.currentCounter-- | ||
requestsSequence.findNewRequestsGeneratorMutex.Unlock() | ||
return requestsSequence.requests[requestsSequence.currentRequestIndex].request | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.