Skip to content

Commit

Permalink
Merge pull request #57 from traveltime-dev/add/precomputed-routes
Browse files Browse the repository at this point in the history
add precomputed routes
  • Loading branch information
danielnaumau authored May 6, 2024
2 parents 848b019 + c765b8c commit d08a67e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ docker run
-e COUNTRY=gb //optional
-e COORDINATES=-8,13 // optional, this will overwrite COUNTRY env var
-e TRANSPORTATION='driving+ferry' //optional
-e DATA_PATH='../precomputed/routes.csv' // optional, this will read coordinates from a file instead of randomly generating them
-e RPM=60 // optional
-e TEST_DURATION=3 //optional, benchmark duration in minutes (not including warmup)
-e UNIQUE_REQUESTS=2 // optional float, percentage of requests that should be unique
Expand Down
3 changes: 3 additions & 0 deletions precomputed/routes.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
origin_lat,origin_lng,dest_lat,dest_lng
48.75653369999993,9.216932199999986,48.82473369999994,9.152635200000017
53.39511600000001,8.708477599999993,53.48773059999998,8.733756700000018
48 changes: 38 additions & 10 deletions scripts/routes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getCurrentStageIndex } from 'https://jslib.k6.io/k6-utils/1.3.0/index.js'
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js'
import {
textSummary
} from 'https://jslib.k6.io/k6-summary/0.0.3/index.js'
Expand Down Expand Up @@ -32,6 +33,8 @@ export const options = {
setThresholdsForScenarios(options)
randomSeed(__ENV.SEED || 1234567)

const precomputedDataFile = __ENV.DATA_PATH ? open(__ENV.DATA_PATH) : undefined

export function setup () {
const appId = __ENV.APP_ID
const apiKey = __ENV.API_KEY
Expand All @@ -53,9 +56,9 @@ export function setup () {
}
}

console.log('The amount of requests generated: ' + uniqueRequestsAmount)

const requestBodies = generateRequestBodies(uniqueRequestsAmount, transportation, countryCoords, dateTime)
const requestBodies = precomputedDataFile
? readRequestsBodies(transportation, dateTime, precomputedDataFile)
: generateRequestBodies(uniqueRequestsAmount, transportation, countryCoords, dateTime)
return { url, requestBodies, params }
}

Expand Down Expand Up @@ -85,18 +88,15 @@ export function handleSummary (data) {
}
}

function generateBody (transportation, countryCoords, dateTime) {
const coordinates = countryCoords
const diff = 0.01

function generateBody (transportation, dateTime, originCoords, destinationCoords) {
const origin = {
id: 'origin',
coords: generateRandomCoordinate(coordinates.lat, coordinates.lng, diff)
coords: originCoords
}

const destination = {
id: 'destination',
coords: generateRandomCoordinate(coordinates.lat, coordinates.lng, diff)
coords: destinationCoords
}

const departureSearches = [{
Expand All @@ -118,6 +118,34 @@ function generateBody (transportation, countryCoords, dateTime) {
})
}

function readRequestsBodies (transportation, dateTime, precomputedDataFile) {
const data = papaparse
.parse(precomputedDataFile, { header: true, skipEmptyLines: true })
.data
.map(route =>
generateBody(
transportation,
dateTime,
{ lat: parseFloat(route.origin_lat), lng: parseFloat(route.origin_lng) },
{ lat: parseFloat(route.dest_lat), lng: parseFloat(route.dest_lng) }
)
)
console.log('The amount of requests read: ' + data.length)
return data
}

function generateRequestBodies (count, transportation, countryCoords, dateTime) {
return Array.from({ length: count }, () => generateBody(transportation, countryCoords, dateTime))
console.log('The amount of requests generated: ' + count)
const diff = 0.01

return Array
.from(
{ length: count },
() => generateBody(
transportation,
dateTime,
generateRandomCoordinate(countryCoords.lat, countryCoords.lng, diff),
generateRandomCoordinate(countryCoords.lat, countryCoords.lng, diff)
)
)
}

0 comments on commit d08a67e

Please sign in to comment.