mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-22 20:48:59 +00:00
Load test tool
This commit is contained in:
parent
cc4e089a5d
commit
affcf8cf41
33
code/tools/load-test/build.gradle
Normal file
33
code/tools/load-test/build.gradle
Normal file
@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id "io.freefair.lombok" version "5.3.3.3"
|
||||
|
||||
id 'jvm-test-suite'
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':code:common:config')
|
||||
implementation project(':code:common:model')
|
||||
implementation project(':code:libraries:term-frequency-dict')
|
||||
implementation libs.lombok
|
||||
annotationProcessor libs.lombok
|
||||
implementation libs.bundles.slf4j
|
||||
implementation libs.notnull
|
||||
}
|
||||
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
task fastTests(type: Test) {
|
||||
useJUnitPlatform {
|
||||
excludeTags "slow"
|
||||
}
|
||||
}
|
9
code/tools/load-test/readme.md
Normal file
9
code/tools/load-test/readme.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Load Test
|
||||
|
||||
Performs random queries to puts load on the local
|
||||
Marginalia deployment to enable profiling of the index.
|
||||
|
||||
Run in the IDE.
|
||||
|
||||
Configure the profiler to look at port 7021 for the index service,
|
||||
and 7023 for the search service.
|
@ -0,0 +1,76 @@
|
||||
package nu.marginalia.load_test;
|
||||
|
||||
import nu.marginalia.WmsaHome;
|
||||
import nu.marginalia.term_frequency_dict.TermFrequencyDict;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LoadTestMain {
|
||||
private static List<String> commonWords;
|
||||
public static void main(String... args) throws URISyntaxException, IOException, InterruptedException {
|
||||
commonWords = loadCommonWords();
|
||||
|
||||
|
||||
System.out.println(commonWords.size());
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
List<Long> times = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
String uri = "http://127.0.0.1:8080/search?query=%s&profile=corpo".formatted(
|
||||
Strings.join(pickNCommonWords(2), '+')
|
||||
);
|
||||
|
||||
HttpRequest req = HttpRequest.newBuilder(new URI(uri))
|
||||
.build();
|
||||
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
var rsp = client.send(req, HttpResponse.BodyHandlers.ofString());
|
||||
long stopTime = System.currentTimeMillis();
|
||||
|
||||
times.add(stopTime - startTime);
|
||||
if (times.size() > 100) {
|
||||
System.out.println(times.stream().mapToLong(Long::longValue).average().orElse(-1));
|
||||
times.clear();
|
||||
}
|
||||
// System.out.println(stopTime - startTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> loadCommonWords() {
|
||||
var dict = new TermFrequencyDict(WmsaHome.getLanguageModels());
|
||||
|
||||
|
||||
try (var lines = Files.lines(Path.of("/usr/share/dict/american-english"))) {
|
||||
return lines.map(String::toLowerCase).filter(term -> dict.getTermFreq(term) > 100000).collect(Collectors.toList());
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static List<String> pickNCommonWords(int n) {
|
||||
assert commonWords.size() > 10*n;
|
||||
|
||||
Set<String> words = new HashSet<>(n);
|
||||
Random r = new Random(System.nanoTime());
|
||||
while (words.size() < n) {
|
||||
words.add(commonWords.get(r.nextInt(0, commonWords.size())));
|
||||
}
|
||||
|
||||
return new ArrayList<>(words);
|
||||
}
|
||||
}
|
@ -63,6 +63,7 @@ include 'code:process-models:crawling-model'
|
||||
include 'code:tools:term-frequency-extractor'
|
||||
include 'code:tools:crawl-job-extractor'
|
||||
include 'code:tools:experiment-runner'
|
||||
include 'code:tools:load-test'
|
||||
|
||||
include 'third-party:porterstemmer'
|
||||
include 'third-party:xz'
|
||||
|
Loading…
Reference in New Issue
Block a user