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

Pivotal ID # 185786866: Simple automated performance test #739

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ fire-itest:
needs: [ "nfs-itest" ]
stage: fire-itest
script: gradle clean :submission:submission-webapp:itest -PenableFire=true --rerun-tasks --stacktrace
variables:
ITEST_FIXED_DELAY: "50"

fire-caos-itest:
needs: [ "fire-itest" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class ITestListener : TestExecutionListener {
private const val ftpUser = "ftpUser"
private const val ftpPassword = "ftpPassword"

internal const val fixedDelayEnv = "ITEST_FIXED_DELAY"
internal val nfsSubmissionPath = testAppFolder.createDirectory("submission")
internal val fireSubmissionPath = testAppFolder.createDirectory("submission-fire")
internal val firePath = testAppFolder.createDirectory("fire-db")
Expand Down Expand Up @@ -159,11 +160,13 @@ class ITestListener : TestExecutionListener {

private fun createFireApiMock(s3MockContainer: S3MockContainer): WireMockServer {
val factor = System.getenv(failFactorEnv)?.toInt()
val delay = System.getenv(fixedDelayEnv)?.toLong() ?: 0L
val transformer = newTransformer(
subFolder = fireSubmissionPath.toPath(),
ftpFolder = fireFtpPath.toPath(),
dbFolder = firePath.toPath(),
failFactor = factor,
fixedDelay = delay,
httpEndpoint = s3MockContainer.httpEndpoint,
defaultBucket = defaultBucket
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ac.uk.ebi.biostd.itest.test.submission.submit

import ac.uk.ebi.biostd.client.integration.commons.SubmissionFormat
import ac.uk.ebi.biostd.client.integration.web.BioWebClient
import ac.uk.ebi.biostd.common.config.FilePersistenceConfig
import ac.uk.ebi.biostd.itest.common.SecurityTestService
import ac.uk.ebi.biostd.itest.entities.SuperUser
import ac.uk.ebi.biostd.itest.itest.ITestListener.Companion.fixedDelayEnv
import ac.uk.ebi.biostd.itest.itest.ITestListener.Companion.tempFolder
import ac.uk.ebi.biostd.itest.itest.getWebClient
import ebi.ac.uk.dsl.tsv.line
import ebi.ac.uk.dsl.tsv.tsv
import ebi.ac.uk.io.ext.createFile
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.server.LocalServerPort
import org.springframework.context.annotation.Import
import org.springframework.test.context.junit.jupiter.SpringExtension
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime

@OptIn(ExperimentalTime::class)
@Import(FilePersistenceConfig::class)
@ExtendWith(SpringExtension::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class SubmissionPerformanceTest(
@Autowired val securityTestService: SecurityTestService,
@LocalServerPort val serverPort: Int,
) {
private lateinit var webClient: BioWebClient

@BeforeAll
fun init() {
securityTestService.ensureUserRegistration(SuperUser)
webClient = getWebClient(serverPort, SuperUser)
}

@Test
@EnabledIfEnvironmentVariable(named = fixedDelayEnv, matches = "\\d+")
@EnabledIfSystemProperty(named = "enableFire", matches = "true")
fun `test with many files`() {
val files = 100
val delay = System.getenv(fixedDelayEnv).toLong()

val subFiles = (1..files).map { tempFolder.createFile("$it.txt") }
webClient.uploadFiles(subFiles)

val performanceSubmission = tsv {
line("Submission", "SPER-1")
line("Title", "Performance Submission")
line()

line("Study")
line()

line("Files")
subFiles.forEach { line(it.name) }
Copy link
Contributor

Choose a reason for hiding this comment

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

The test looks awesome, I think this is worth measuring. I think it could benefit from adding the files through a file list rather than placing them directly in the submission just to add to the test case the overhead of reading the file list at each stage which is our most common case for big submissions.

Also, I think we could increase the number of files to 1000. It'll add an extra minute but the test will be closer to our actual use case.

WDYT?

Copy link
Contributor Author

@Juan-EBI Juan-EBI Aug 10, 2023

Choose a reason for hiding this comment

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

I think it is not a real performance test but rather a simple exercise to monitor performance in really really ideail conditions, I agree with using file list as this does help to test batch processing but 1000 files will be still an small number of files so I do not see much value there. We may think to use 1.000.000 but again this is not a real performance test so IMO it will not add much information than using 100 and will delay test execution.

Copy link
Contributor Author

@Juan-EBI Juan-EBI Aug 10, 2023

Choose a reason for hiding this comment

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

actually just test it with 1000 and runner JVM dies (and I think updating runner to match production machine and get "real performance" is out of the scope)

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, maybe the execution is too long. I'd still like to see the files in a file list but I'll leave it to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

files are inded in a file list already

line()
}.toString()

val executionTime = measureTime { webClient.submitSingle(performanceSubmission, SubmissionFormat.TSV) }

// Execution time is bounded by 9 times the delay on each Fire operation
val expectedTime = (9.0 * (files * delay)).toLong()
assertThat(executionTime.inWholeMilliseconds).isLessThan(expectedTime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kotlin.random.Random

class TestWireMockTransformer constructor(
private val failFactor: Int?,
private val fixedDelay: Long,
private val handlers: List<RequestHandler>,
) : ResponseDefinitionTransformer() {
override fun getName(): String = Companion.name
Expand All @@ -37,6 +38,7 @@ class TestWireMockTransformer constructor(
files: FileSource?,
parameters: Parameters?,
): ResponseDefinition {
Thread.sleep(fixedDelay)
return failIfApply()
?: handlers.firstOrNull { it.urlPattern.matches(rqt.url) && it.method == rqt.method }?.handleSafely(rqt)
?: throw WebClientException(HttpStatus.BAD_REQUEST, "http method ${rqt.method.name} is not supported")
Expand All @@ -57,6 +59,7 @@ class TestWireMockTransformer constructor(
ftpFolder: Path,
dbFolder: Path,
failFactor: Int?,
fixedDelay: Long,
httpEndpoint: String,
defaultBucket: String,
): TestWireMockTransformer {
Expand All @@ -66,6 +69,7 @@ class TestWireMockTransformer constructor(

return TestWireMockTransformer(
failFactor,
fixedDelay,
listOf(
Md5QueryHandler(fireDatabase),
FileSaveHandler(fireDatabase),
Expand Down