load tester supports changing host, port and payload

This commit is contained in:
Lex Berezhny 2019-07-11 16:13:16 -04:00
parent cc098f3090
commit 5bceb06fc5
2 changed files with 34 additions and 31 deletions

View file

@ -4,28 +4,8 @@ import 'dart:convert';
class LoadRequest { class LoadRequest {
final String host;
static const RESOLVE = { final int port;
'id': 1,
'method': 'blockchain.claimtrie.resolve',
'params': ['one', 'two', 'three']
};
static const CLAIM_SEARCH = {
'id': 1,
'method': 'blockchain.claimtrie.search',
'params': {
'fee_amount': '<1',
'all_tags': ['funny'],
'any_tags': [
'crypto',
'outdoors',
'cars',
'automotive'
]
}
};
final Map payload; final Map payload;
Completer completer; Completer completer;
Stopwatch timer; Stopwatch timer;
@ -33,15 +13,14 @@ class LoadRequest {
bool get isDone => completer.isCompleted; bool get isDone => completer.isCompleted;
int get elapsed => timer.elapsedMilliseconds; int get elapsed => timer.elapsedMilliseconds;
LoadRequest.search(): payload=CLAIM_SEARCH; LoadRequest(this.host, this.port, this.payload);
LoadRequest.resolve(): payload=RESOLVE;
LoadRequest start() { LoadRequest start() {
completer = Completer(); completer = Completer();
timer = Stopwatch()..start(); timer = Stopwatch()..start();
completer.future.whenComplete(() => timer.stop()); completer.future.whenComplete(() => timer.stop());
try { try {
Socket.connect('127.0.0.1', 50001).then((socket) { Socket.connect(this.host, this.port).then((socket) {
socket.transform(utf8.decoder).listen((r) { socket.transform(utf8.decoder).listen((r) {
if (r.contains('"jsonrpc": "2.0", "result": ')) { if (r.contains('"jsonrpc": "2.0", "result": ')) {
socket.close(); socket.close();
@ -70,10 +49,13 @@ typedef bool LoadTestCallback(LoadGenerator load_generator, LoadDataPoint stats)
class LoadGenerator { class LoadGenerator {
int load = 1; int load = 1;
Timer _timer; Timer _timer;
String host;
int port;
Map query;
LoadTestCallback cb; LoadTestCallback cb;
LoadGenerator(this.cb); LoadGenerator(this.host, this.port, this.query, this.cb);
start() { start() {
var previous = spawn_requests(); var previous = spawn_requests();
@ -108,7 +90,7 @@ class LoadGenerator {
List<LoadRequest> spawn_requests() { List<LoadRequest> spawn_requests() {
var requests = <LoadRequest>[]; var requests = <LoadRequest>[];
for (var _ in Iterable.generate(load)) { for (var _ in Iterable.generate(load)) {
requests.add(LoadRequest.search().start()); requests.add(LoadRequest(this.host, this.port, this.query).start());
} }
return requests; return requests;
} }
@ -139,7 +121,11 @@ class LoadDataPoint {
cli() { cli() {
var runs = 1; var runs = 1;
LoadGenerator((t, stats) { LoadGenerator('localhost', 50001, {
'id': 1,
'method': 'blockchain.claimtrie.resolve',
'params': ['one', 'two', 'three']
}, (t, stats) {
print("run ${runs}: ${stats}"); print("run ${runs}: ${stats}");
t.load = (runs < 4 ? t.load*2 : t.load/2).round(); t.load = (runs < 4 ? t.load*2 : t.load/2).round();
return runs++ < 10; return runs++ < 10;

View file

@ -77,14 +77,31 @@ class _SimpleTimeSeriesChartState extends State<SimpleTimeSeriesChart> {
data: loadData, data: loadData,
) )
); );
var increase = 2; var increase = 1;
loadData.add(LoadDataPoint()); loadData.add(LoadDataPoint());
loadGenerator = LoadGenerator((t, stats) { loadGenerator = LoadGenerator('spv2.lbry.com', 50001, {
'id': 1,
'method': 'blockchain.claimtrie.search',
'params': {
'offset': 0,
'limit': 20,
'fee_amount': '<1',
'all_tags': ['funny'],
'any_tags': [
'crypto',
'outdoors',
'cars',
'automotive'
]
}
}, (t, stats) {
setState(() { setState(() {
//if (loadData.length > 60) loadData.removeAt(0); //if (loadData.length > 60) loadData.removeAt(0);
loadData.add(stats); loadData.add(stats);
}); });
increase = max(1, min(30, (increase*1.1).ceil())-stats.backlog); //increase = max(1, min(30, (increase*1.1).ceil())-stats.backlog);
increase += 1;
//t.query['params']['offset'] = (increase/2).ceil()*t.query['params']['limit'];
t.load = increase;//rand.nextInt(10)+5; t.load = increase;//rand.nextInt(10)+5;
return true; return true;
})..start(); })..start();