From 5bceb06fc5962c05a6c2ae0c1f687f44c4f2a705 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Thu, 11 Jul 2019 16:13:16 -0400 Subject: [PATCH] load tester supports changing host, port and payload --- .../packages/lbry/lib/src/load_generator.dart | 42 +++++++------------ dart/packages/ver/lib/time_series_chart.dart | 23 ++++++++-- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/dart/packages/lbry/lib/src/load_generator.dart b/dart/packages/lbry/lib/src/load_generator.dart index 380970268..f31371569 100644 --- a/dart/packages/lbry/lib/src/load_generator.dart +++ b/dart/packages/lbry/lib/src/load_generator.dart @@ -4,28 +4,8 @@ import 'dart:convert'; class LoadRequest { - - static const RESOLVE = { - '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 String host; + final int port; final Map payload; Completer completer; Stopwatch timer; @@ -33,15 +13,14 @@ class LoadRequest { bool get isDone => completer.isCompleted; int get elapsed => timer.elapsedMilliseconds; - LoadRequest.search(): payload=CLAIM_SEARCH; - LoadRequest.resolve(): payload=RESOLVE; + LoadRequest(this.host, this.port, this.payload); LoadRequest start() { completer = Completer(); timer = Stopwatch()..start(); completer.future.whenComplete(() => timer.stop()); try { - Socket.connect('127.0.0.1', 50001).then((socket) { + Socket.connect(this.host, this.port).then((socket) { socket.transform(utf8.decoder).listen((r) { if (r.contains('"jsonrpc": "2.0", "result": ')) { socket.close(); @@ -70,10 +49,13 @@ typedef bool LoadTestCallback(LoadGenerator load_generator, LoadDataPoint stats) class LoadGenerator { int load = 1; Timer _timer; + String host; + int port; + Map query; LoadTestCallback cb; - LoadGenerator(this.cb); + LoadGenerator(this.host, this.port, this.query, this.cb); start() { var previous = spawn_requests(); @@ -108,7 +90,7 @@ class LoadGenerator { List spawn_requests() { var requests = []; for (var _ in Iterable.generate(load)) { - requests.add(LoadRequest.search().start()); + requests.add(LoadRequest(this.host, this.port, this.query).start()); } return requests; } @@ -139,7 +121,11 @@ class LoadDataPoint { cli() { 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}"); t.load = (runs < 4 ? t.load*2 : t.load/2).round(); return runs++ < 10; diff --git a/dart/packages/ver/lib/time_series_chart.dart b/dart/packages/ver/lib/time_series_chart.dart index ebbdaafb6..c184efc9b 100644 --- a/dart/packages/ver/lib/time_series_chart.dart +++ b/dart/packages/ver/lib/time_series_chart.dart @@ -77,14 +77,31 @@ class _SimpleTimeSeriesChartState extends State { data: loadData, ) ); - var increase = 2; + var increase = 1; 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(() { //if (loadData.length > 60) loadData.removeAt(0); 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; return true; })..start();