initial load testing script
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/simple-load-tester.iml" filepath="$PROJECT_DIR$/.idea/simple-load-tester.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
9
.idea/simple-load-tester.iml
generated
Normal file
9
.idea/simple-load-tester.iml
generated
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
195
index.html
Normal file
195
index.html
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Load Test Results</title>
|
||||||
|
<style>
|
||||||
|
svg {
|
||||||
|
width: 500px;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
.bar {
|
||||||
|
fill: steelblue;
|
||||||
|
}
|
||||||
|
.err {
|
||||||
|
fill: red;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Load Test Results</h1>
|
||||||
|
<svg id="chart"></svg>
|
||||||
|
<svg id="chart2"></svg>
|
||||||
|
<svg id="chart3"></svg>
|
||||||
|
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.4/d3.min.js" integrity="sha512-nfUlp2ZWPKWlnAH/OsMeAqRSYBxOdPYeBXwceyw6QqqZ7uTT/s5/eS1hMKphjVBouk0jf/JQ8ULVJRnEqSHkXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<script>
|
||||||
|
d3.json("load_test_results.json").then(function(data) {
|
||||||
|
// Sort the data by StartTime
|
||||||
|
data.sort(function(a, b) {
|
||||||
|
return a.StartTime - b.StartTime;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Define the chart dimensions
|
||||||
|
var margin = { top: 20, right: 20, bottom: 30, left: 40 };
|
||||||
|
var width = 500 - margin.left - margin.right;
|
||||||
|
var height = 300 - margin.top - margin.bottom;
|
||||||
|
|
||||||
|
// Create the SVG element
|
||||||
|
var svg = d3.select("#chart")
|
||||||
|
.attr("width", width + margin.left + margin.right)
|
||||||
|
.attr("height", height + margin.top + margin.bottom)
|
||||||
|
.append("g")
|
||||||
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||||
|
|
||||||
|
// Define the scales
|
||||||
|
var xScale = d3.scaleBand()
|
||||||
|
.range([0, width])
|
||||||
|
.padding(0.1)
|
||||||
|
.domain(data.map(function(d) { return d.RequestNumber; }));
|
||||||
|
|
||||||
|
var yScale = d3.scaleLinear()
|
||||||
|
.range([height, 0])
|
||||||
|
.domain([0, d3.max(data, function(d) { return d.Duration; })]);
|
||||||
|
|
||||||
|
// Create the bars
|
||||||
|
svg.selectAll(".bar")
|
||||||
|
.data(data)
|
||||||
|
.enter().append("rect")
|
||||||
|
.attr("class", function(d) { return d.IsError ? "err" : "bar"; })
|
||||||
|
.attr("x", function(d) { return xScale(d.RequestNumber); })
|
||||||
|
.attr("y", height)
|
||||||
|
.attr("width", xScale.bandwidth())
|
||||||
|
.attr("height", 0)
|
||||||
|
.transition()
|
||||||
|
.duration(1000)
|
||||||
|
.attr("y", function(d) { return yScale(d.Duration); })
|
||||||
|
.attr("height", function(d) { return height - yScale(d.Duration); });
|
||||||
|
|
||||||
|
// Add axes
|
||||||
|
svg.append("g")
|
||||||
|
.attr("transform", "translate(0," + height + ")")
|
||||||
|
.call(d3.axisBottom(xScale));
|
||||||
|
|
||||||
|
svg.append("g")
|
||||||
|
.call(d3.axisLeft(yScale));
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
d3.json("load_test_results.json").then(function(data) {
|
||||||
|
// Sort the data by StartTime
|
||||||
|
data.sort(function(a, b) {
|
||||||
|
return a.StartTime - b.StartTime;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Define the chart dimensions
|
||||||
|
var margin = { top: 20, right: 20, bottom: 30, left: 40 };
|
||||||
|
var width = 500 - margin.left - margin.right;
|
||||||
|
var height = 300 - margin.top - margin.bottom;
|
||||||
|
|
||||||
|
// Create the SVG element
|
||||||
|
var svg = d3.select("#chart2")
|
||||||
|
.attr("width", width + margin.left + margin.right)
|
||||||
|
.attr("height", height + margin.top + margin.bottom)
|
||||||
|
.append("g")
|
||||||
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||||
|
|
||||||
|
// Define the scales
|
||||||
|
var xScale = d3.scaleLinear()
|
||||||
|
.range([0, width])
|
||||||
|
.domain([d3.min(data, function(d) { return d.StartTime; }), d3.max(data, function(d) { return d.StartTime + d.Duration; })]);
|
||||||
|
|
||||||
|
var yScale = d3.scaleLinear()
|
||||||
|
.range([height, 0])
|
||||||
|
.domain([0, d3.max(data, function(d) { return d.Duration; })]);
|
||||||
|
|
||||||
|
// Create the bars
|
||||||
|
svg.selectAll(".bar")
|
||||||
|
.data(data)
|
||||||
|
.enter().append("rect")
|
||||||
|
.attr("class", "bar")
|
||||||
|
// .attr("x", function(d) { return xScale(d.StartTime); })
|
||||||
|
.attr("x", function(d) { return xScale(d.StartTime + d.Duration); })
|
||||||
|
.attr("y", height)
|
||||||
|
.attr("width", 1)
|
||||||
|
.attr("height", 0)
|
||||||
|
.transition()
|
||||||
|
.duration(1000)
|
||||||
|
.attr("y", function(d) { return yScale(d.Duration); })
|
||||||
|
.attr("height", function(d) { return height - yScale(d.Duration); });
|
||||||
|
|
||||||
|
// Add axes
|
||||||
|
svg.append("g")
|
||||||
|
.attr("transform", "translate(0," + height + ")")
|
||||||
|
.call(d3.axisBottom(xScale).tickFormat(function(d) { return new Date(d / 1000000).toISOString().substr(11, 8); }));
|
||||||
|
|
||||||
|
svg.append("g")
|
||||||
|
.call(d3.axisLeft(yScale));
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
d3.json("load_test_results.json").then(function(data) {
|
||||||
|
// Count the number of true and false values of IsError
|
||||||
|
var trueCount = data.reduce(function(acc, val) {
|
||||||
|
return acc + (val.IsError ? 1 : 0);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
var falseCount = data.length - trueCount;
|
||||||
|
|
||||||
|
// Prepare the data for the chart
|
||||||
|
var chartData = [
|
||||||
|
{ label: "True", count: trueCount },
|
||||||
|
{ label: "False", count: falseCount }
|
||||||
|
];
|
||||||
|
|
||||||
|
// Define the chart dimensions
|
||||||
|
var margin = { top: 20, right: 20, bottom: 30, left: 40 };
|
||||||
|
var width = 500 - margin.left - margin.right;
|
||||||
|
var height = 300 - margin.top - margin.bottom;
|
||||||
|
|
||||||
|
// Create the SVG element
|
||||||
|
var svg = d3.select("#chart3")
|
||||||
|
.attr("width", width + margin.left + margin.right)
|
||||||
|
.attr("height", height + margin.top + margin.bottom)
|
||||||
|
.append("g")
|
||||||
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||||
|
|
||||||
|
// Define the scales
|
||||||
|
var xScale = d3.scaleBand()
|
||||||
|
.range([0, width])
|
||||||
|
.padding(0.1)
|
||||||
|
.domain(chartData.map(function(d) { return d.label; }));
|
||||||
|
|
||||||
|
var yScale = d3.scaleLinear()
|
||||||
|
.range([height, 0])
|
||||||
|
.domain([0, d3.max(chartData, function(d) { return d.count; })]);
|
||||||
|
|
||||||
|
// Create the bars
|
||||||
|
svg.selectAll(".bar")
|
||||||
|
.data(chartData)
|
||||||
|
.enter().append("rect")
|
||||||
|
.attr("class", "bar")
|
||||||
|
.attr("x", function(d) { return xScale(d.label); })
|
||||||
|
.attr("y", height)
|
||||||
|
.attr("width", xScale.bandwidth())
|
||||||
|
.attr("height", 0)
|
||||||
|
.transition()
|
||||||
|
.duration(1000)
|
||||||
|
.attr("y", function(d) { return yScale(d.count); })
|
||||||
|
.attr("height", function(d) { return height - yScale(d.count); });
|
||||||
|
|
||||||
|
// Add axes
|
||||||
|
svg.append("g")
|
||||||
|
.attr("transform", "translate(0," + height + ")")
|
||||||
|
.call(d3.axisBottom(xScale));
|
||||||
|
|
||||||
|
svg.append("g")
|
||||||
|
.call(d3.axisLeft(yScale));
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
1
load_test_results.json
Normal file
1
load_test_results.json
Normal file
File diff suppressed because one or more lines are too long
98
main.go
Normal file
98
main.go
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RequestData struct {
|
||||||
|
RequestNumber int
|
||||||
|
StartTime int64
|
||||||
|
Duration int64
|
||||||
|
IsError bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeRequest(url string, requestNumber int, wg *sync.WaitGroup, results chan<- RequestData) {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
startTime := time.Now().UnixNano()
|
||||||
|
httpClient := http.Client{
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSHandshakeTimeout: 30 * time.Second,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := httpClient.Get(url)
|
||||||
|
//resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error making request %d: %v\n", requestNumber, err)
|
||||||
|
results <- RequestData{
|
||||||
|
RequestNumber: requestNumber,
|
||||||
|
StartTime: startTime,
|
||||||
|
Duration: time.Now().UnixNano() - startTime,
|
||||||
|
IsError: true,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
duration := time.Now().UnixNano() - startTime
|
||||||
|
results <- RequestData{
|
||||||
|
RequestNumber: requestNumber,
|
||||||
|
StartTime: startTime,
|
||||||
|
Duration: duration,
|
||||||
|
IsError: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Define your API URL and number of requests to make
|
||||||
|
apiURL := "https://git.sa.vin"
|
||||||
|
numRequests := 1000
|
||||||
|
//numRequests := 596
|
||||||
|
|
||||||
|
// Create a channel to collect the request results
|
||||||
|
results := make(chan RequestData, numRequests)
|
||||||
|
|
||||||
|
// Create a WaitGroup to synchronize goroutines
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(numRequests)
|
||||||
|
|
||||||
|
// Start load testing by spawning goroutines
|
||||||
|
for i := 0; i < numRequests; i++ {
|
||||||
|
go makeRequest(apiURL, i, &wg, results)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for all goroutines to finish
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
// Close the results channel
|
||||||
|
close(results)
|
||||||
|
|
||||||
|
// Collect the results from the channel
|
||||||
|
var requestData []RequestData
|
||||||
|
for result := range results {
|
||||||
|
requestData = append(requestData, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Marshal the data to JSON
|
||||||
|
jsonData, err := json.Marshal(requestData)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error marshaling JSON: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the JSON data to disk
|
||||||
|
err = os.WriteFile("load_test_results.json", jsonData, 0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error writing JSON file: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Load testing completed. Results stored in load_test_results.json")
|
||||||
|
}
|
Reference in New Issue
Block a user