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

download compression is too slow #727

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class LapisSpringConfig {
filter.setIncludePayload(true)
filter.setMaxPayloadLength(10000)
filter.setIncludeHeaders(false)
filter.setAfterMessagePrefix("REQUEST DATA: ")
return filter
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ class CompressingServletOutputStream(
compressingStream.write(byte)
}

override fun write(bytes: ByteArray) {
compressingStream.write(bytes)
}

override fun write(
bytes: ByteArray,
offset: Int,
length: Int,
) {
compressingStream.write(bytes, offset, length)
}
Comment on lines +225 to +235
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chaoran-chen Those are the relevant changes. We didn't forward those methods to the compressing stream. Instead, the default implementation would call fun write(byte: Int) for every entry of the ByteArray. Apparently the compression streams can do a lot better than writing every byte individually.


override fun isReady() = outputStream.isReady

override fun setWriteListener(listener: WriteListener?) = outputStream.setWriteListener(listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RequestContext {
var endpoint: String? = null
var filter: CommonSequenceFilters? = null
var responseCode: Int? = null
var cached: Boolean? = null
}

private val log = KotlinLogging.logger {}
Expand Down
20 changes: 17 additions & 3 deletions lapis2/src/main/kotlin/org/genspectrum/lapis/silo/SiloClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import mu.KotlinLogging
import org.genspectrum.lapis.controller.LapisHeaders.REQUEST_ID
import org.genspectrum.lapis.logging.RequestContext
import org.genspectrum.lapis.logging.RequestIdContext
import org.genspectrum.lapis.response.InfoData
import org.springframework.beans.factory.annotation.Value
Expand All @@ -27,14 +28,22 @@ const val SILO_RESPONSE_MAX_LOG_LENGTH = 10_000
class SiloClient(
private val cachedSiloClient: CachedSiloClient,
private val dataVersion: DataVersion,
private val requestContext: RequestContext,
) {
fun <ResponseType> sendQuery(query: SiloQuery<ResponseType>): ResponseType {
val result = cachedSiloClient.sendQuery(query)
dataVersion.dataVersion = result.dataVersion

if (RequestContextHolder.getRequestAttributes() != null && requestContext.cached == null) {
requestContext.cached = true
}

return result.queryResult
}

fun callInfo(): InfoData {
log.info { "Calling SILO info" }

val info = cachedSiloClient.callInfo()
dataVersion.dataVersion = info.dataVersion
return info
Expand All @@ -48,11 +57,16 @@ class CachedSiloClient(
@Value("\${silo.url}") private val siloUrl: String,
private val objectMapper: ObjectMapper,
private val requestIdContext: RequestIdContext,
private val requestContext: RequestContext,
) {
private val httpClient = HttpClient.newHttpClient()

@Cacheable(SILO_QUERY_CACHE_NAME, condition = "#query.action.cacheable && !#query.action.randomize")
fun <ResponseType> sendQuery(query: SiloQuery<ResponseType>): WithDataVersion<ResponseType> {
if (RequestContextHolder.getRequestAttributes() != null) {
requestContext.cached = false
}

val queryJson = objectMapper.writeValueAsString(query)

log.info { "Calling SILO: $queryJson" }
Expand All @@ -74,8 +88,6 @@ class CachedSiloClient(
}

fun callInfo(): InfoData {
log.info { "Calling SILO info" }

val response = send(URI("$siloUrl/info")) { it.GET() }

return InfoData(getDataVersion(response))
Expand All @@ -101,7 +113,9 @@ class CachedSiloClient(
throw RuntimeException(message, exception)
}

log.info { "Response from SILO: ${response.statusCode()}" }
if (!uri.toString().endsWith("info")) {
log.info { "Response from SILO: ${response.statusCode()}" }
}
log.debug {
val body = response.body()
val truncationPostfix = when {
Expand Down
Loading