Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tracemalloc utility view to API and improve k6 scripts for memory leak debugging #3046

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Only use random words that definitely have results
  • Loading branch information
sarayourfriend committed Sep 20, 2023
commit 676afa094b32c7fe11a11d2e252730ea689c0c21
3 changes: 3 additions & 0 deletions utilities/load_testing/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ api host=("http://" + DOCKER_HOST + ":8000"):

k6 url="https://api-dev.openverse.engineering" +extra_args="": build
docker run --rm -e API_TOKEN=$API_TOKEN -e API_URL={{ url }} -v {{ invocation_directory() }}/k6:/app {{ extra_args }} openverse-load-testing:latest k6 run main.js

k6-local:
@API_TOKEN="" just k6 http://localhost:50280/v1/ --net=host
Comment on lines +17 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent, thanks for adding it!

5 changes: 2 additions & 3 deletions utilities/load_testing/k6/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { group } from "k6"
import { searchBy } from "./search.js"
import { getProvider, getRandomWord } from "./utils.js"
import { getProvider } from "./utils.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 40-41:

    provider_image_page_20: createScenario("images", "20", "searchByProvider"),
    provider_image_page_500: createScenario("images", "500", "searchByProvider"),


const createScenario = (mediaType, pageSize, funcName) => {
return {
Expand Down Expand Up @@ -64,7 +64,6 @@ const searchByField = (paramFunc, followLinks = false) => {
)
}

export const searchByRandomWord = () =>
searchByField(() => `q=${getRandomWord()}`, true)
export const searchByRandomWord = () => searchByField(() => `randomWord`, true)
export const searchByProvider = () =>
searchByField((media_type) => `source=${getProvider(media_type)}`, false)
11 changes: 10 additions & 1 deletion utilities/load_testing/k6/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ import {
makeResponseFailedCheck,
REQUEST_HEADERS,
SLEEP_DURATION,
discoveredUnconsumedTags,
getRandomWord,
} from "./utils.js"

export const searchBy = (param, page, media_type, page_size, followLinks) => {
let url = `${API_URL}${media_type}/?${param}&page=${page}&page_size=${page_size}&filter_dead=false`
if (param === "randomWord") {
param = `q=${getRandomWord()}`
}

let url = `${API_URL}${media_type}/?${param}&page=${page}&page_size=${page_size}&filter_dead=true`
const response = http.get(url, { headers: REQUEST_HEADERS })

const checkResponseFailed = makeResponseFailedCheck(param, page)
Expand All @@ -23,6 +29,9 @@ export const searchBy = (param, page, media_type, page_size, followLinks) => {
const pageCount = parsedResp["page_count"]
const detailUrls = parsedResp["results"].map((i) => i.detail_url)
const relatedUrls = parsedResp["results"].map((i) => i.related_url)
parsedResp["results"].forEach((i) =>
i["tags"].forEach((t) => discoveredUnconsumedTags.add(t["name"]))
)

// Don't view details/related if not requested
if (!followLinks) {
Expand Down
15 changes: 10 additions & 5 deletions utilities/load_testing/k6/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { randomItem } from "https://jslib.k6.io/k6-utils/1.2.0/index.js"
export const API_URL =
__ENV.API_URL || "https://api-dev.openverse.engineering/v1/"
export const SLEEP_DURATION = 0.1
// Use the random words list available locally, but filter any words that end with apostrophe-s
const WORDS = open("/usr/share/dict/words")
.split("\n")
.filter((w) => !w.endsWith("'s"))

export const getRandomWord = () => randomItem(WORDS)
export const discoveredUnconsumedTags = new Set()

export const getRandomWord = () => {
if (discoveredUnconsumedTags.size) {
const tag = randomItem(Array.from(discoveredUnconsumedTags))
discoveredUnconsumedTags.delete(tag)
return tag
}
return randomItem(["dog", "run", "cat", "honey", "happy"])
}

export const getProvider = (media_type) => {
let url = `${API_URL}${media_type}/stats`
Expand Down