Skip to content

Commit

Permalink
Merge pull request #17 from ktorio/bjhham/3.0.0
Browse files Browse the repository at this point in the history
Improvements for allocation tests for 3.0.0
  • Loading branch information
bjhham committed Dec 8, 2023
2 parents 91b7b25 + c511f95 commit 3ef2d8e
Show file tree
Hide file tree
Showing 25 changed files with 50,579 additions and 9,723 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# ktor-benchmarks
# Ktor Benchmarks

This repository contains benchmark tests for various performance metrics.

### Allocation Benchmark (/allocation-benchmark)

Tests how much memory is allocated on a given request. This is done before every merge to ensure that the ktor server
maintains a low memory profile by avoiding erroneous allocations.

**Testing:** `ServerCallAllocationTest` runs through the supported engines and calculates the memory allocated per request. When a new baseline is required,
you may run the `dumpAllocations` gradle target.

**Inspection:** the allocation baseline dump is a series of JSON files. For easy reading of the values exported here, use the `reportServer` gradle target
which has two pages for inspecting where memory is being allocated. `previewClasses.html` shows the largest memory consumers for types allocated, and
`previewSites.html` shows the code sites that allocate the most memory.

**TeamCity:** [https://ktor.teamcity.com/buildConfiguration/Ktor_AllocationTests](https://ktor.teamcity.com/buildConfiguration/Ktor_AllocationTests)
53 changes: 53 additions & 0 deletions allocation-benchmark/allocations/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

const formatSize = (size) => Math.round(size / 1024 / 1024 * 1000) / 1000 + "Mb"

export function displaySite(sites, item) {
const site = sites.append("div")
.attr("class", "site")
.attr("data-expand", "false")

const stackTrace = item.stackTrace.split(", ")

const siteElem = site.append("div")
.attr("class", "header")
siteElem.append("div").attr("class", "chevron")
siteElem.append("span")
.style("font-weight", "bold")
.text(`${formatSize(item.totalSize)} (${item.totalCount})`)
siteElem.append("span")
.text(stackTrace[1].split(" ")[0])
siteElem.on("click", () => {
site.attr("data-expand", site.attr("data-expand") === "false")
})

const stack = site.append("ul")
.attr("class", "stacktrace")
.style("list-style-type", "none")

stackTrace.forEach((stackItem) => {
const li = stack.append("li")
const [file, fun] = stackItem.split(" ")
li.append("span").attr("class", "file").text(file)
li.append("span").attr("class", "fun").text(fun)
})
}

export function setupRenderControls(drawAllocations) {
const render = () => {
const engineName = document.querySelector("input[name='engine']:checked").value
const snapshotDir = document.querySelector("input[name='snapshot']:checked").value
const reportPath = `${snapshotDir}/testMemoryConsumptionIsSame[${engineName}].json`;
d3.json(reportPath).then(result => {
drawAllocations(result.data)
document.getElementById("info").innerText = ""
}, () => {
drawAllocations({})
document.getElementById("info").innerText = `Nothing found for ${reportPath}`
})
}
document.querySelectorAll("input[type='radio']").forEach(elem => {
elem.onchange = render
})

render()
}
Loading

0 comments on commit 3ef2d8e

Please sign in to comment.