Hi there,
I have a dependency to log the response time for each request during the whole test. So, I have record the timestamp before and after the request has been executed. However, I observed some differences between the gatling report and logged values.
This is the gatling result for my test:
================================================================================
---- Global Information --------------------------------------------------------
> request count 1468243 (OK=1414263 KO=53980 )
> min response time 23 (OK=23 KO=23 )
> max response time 3080 (OK=3080 KO=2384 )
> mean response time 67 (OK=67 KO=47 )
> std deviation 131 (OK=132 KO=85 )
> response time 50th percentile 38 (OK=38 KO=33 )
> response time 75th percentile 51 (OK=51 KO=41 )
> response time 95th percentile 157 (OK=162 KO=74 )
> response time 99th percentile 767 (OK=774 KO=380 )
> mean requests/sec 2447.072 (OK=2357.105 KO=89.967)
But in my log file, when I checked for the number of records greater than 767 milliseconds, it was 1233265 requests(which is around 80% of total requests).
Below is the snippet of the log file:
2024-01-01T09:56:42Z,1704103003875,998
2024-01-01T09:56:42Z,1704103003875,981
2024-01-01T09:56:42Z,1704103003875,971
2024-01-01T09:56:42Z,1704103003876,974
2024-01-01T09:56:42Z,1704103003876,967
2024-01-01T09:56:42Z,1704103003876,982
2024-01-01T09:56:42Z,1704103003876,972
2024-01-01T09:56:42Z,1704103003876,978
2024-01-01T09:56:42Z,1704103003877,985
2024-01-01T09:56:42Z,1704103003877,986
2024-01-01T09:56:42Z,1704103003880,970
2024-01-01T09:56:42Z,1704103003881,988
2024-01-01T09:56:42Z,1704103003881,989
2024-01-01T09:56:42Z,1704103003882,987
2024-01-01T09:56:42Z,1704103003882,1004
2024-01-01T09:56:42Z,1704103003883,1010
Below is my code:
def getUTCOffsetInMS: String = {
val currentUTCTime: ZonedDateTime = ZonedDateTime.now(ZoneId.of("UTC"))
currentUTCTime.toInstant.toEpochMilli.toString
}
def convertMillisecondsToDate(milliseconds: Long): String = {
val dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"))
val utcDate = new Date(milliseconds)
dateFormat.format(utcDate)
}
def logRequestForOldRec(req: HttpRequestBuilder, reqName: String, writer: FileOutputStream, isLogNeeded: Boolean = true): ChainBuilder ={
doIfOrElse(isLogNeeded) {
exec(session => {
val startTime: Long = getUTCOffsetInMS.toLong
session.setAll(Map("startTime" -> startTime))
})
.exec(req)
.exec(session => {
val currentUTCTimeMillis: Long = getUTCOffsetInMS.toLong
val total = currentUTCTimeMillis - session("startTime").as[Long]
val utcAbsTime = convertMillisecondsToDate(session("startTime").as[Long])
val logStr = s"$utcAbsTime,$currentUTCTimeMillis,$total\n"
writer.write(logStr.getBytes(), 0, logStr.length)
session
})
}
{
exec(req)
}
}