I need to stream a relatively large file (300-500 ...
# ktor
I need to stream a relatively large file (300-500 MB) concurrently to 10+ clients, but under load, the download speed gets super low (down to 300 kb/s). It feels like the server doesn't have enough resources to process such amount of long-running requests ­čĄö Environment: OS: Windows 10 x64 CPU: Intel Core i9-10900k RAM: 32 GB Code:
Copy code
fun main() {
    val file = File("G:/test.zip")

    embeddedServer(CIO, port = 8081) {
        routing {
            get("/file") {
                call.response.header(HttpHeaders.ContentDisposition, "inline; filename=\"test.zip\"")

                call.respondOutputStream {
                    file.inputStream().buffered().use { stream -> stream.copyTo(this.buffered()) }
So what is a good way to debug it? Or maybe there is a better approach I can use?
you're reading the file from disk every request? given your available ram, you could try loading it once instead.
@Emil Kantis I tried this, same behaviour =(
Did you try to read a file contents into a ByteArray and then just respond with bytes?
@Aleksei Tirman [JB] It doesn't matter, I even tried generating random bytes on every request.
The problem was stupid as always - I tested on a slow SSD.