JetBrains / kotlin-compiler-server

Server for executing kotlin code
Apache License 2.0
240 stars 73 forks source link

Process multiple run requests #724

Open devaxolotl opened 4 months ago

devaxolotl commented 4 months ago

I'm trying to set up kotlin-compiler-server but have run into something I don't know how to get past.

I am able to run the server but it looks like it will only process one request at a time. If I send a request that takes 10 seconds and then send another request the second request only starts after the first request completes.

Is this the expected behavior? Is it possible to get it to process multiple requests at the same time?

nikpachoo commented 4 months ago

Hi @devaxolotl! I checked it locally and couldn't reproduce the issue. A couple of requests were completed simultaneously. Please share more details if the problem remains so we can reproduce your case.

devaxolotl commented 4 months ago

Thank you for the reply @nikpachoo, here are more details on what I am trying:

  1. Cloned the repo
  2. Built the Docker image using ./docker-image-build.sh
  3. Ran it in a docker container using
docker run -d -p 8080:8080 --name kotlin-compiler-server [id of image]
  1. At this point I am able to access the REST endpoints
  2. Using the endpoint /api/compiler/run I set up two REST clients
  3. In one client I set up this call
POST http://localhost:8080/api/compiler/run
Content-Type: application/json

{
    "args": "1 2 3",
    "files": [
        {
            "name": "File.kt",
            "text": "fun main() {\n    Thread.sleep(5000L)\n\n    println(\"5 seconds has passed\")\n}"
        }
    ]
}

In another client I set up this call:

POST http://localhost:8080/api/compiler/run
Content-Type: application/json

{
    "args": "1 2 3",
    "files": [
        {
            "name": "File.kt",
            "text": "fun main() {\n    println(\"second call\")\n}"
        }
    ]
}
  1. Now I run the first call that sleeps then immediately run the second call after that. The second call seems to only return after the first one returns or times out.

I also tried it with a long running call instead of using sleep or timers.

fun main() {
    val n = 45
    println("Fibonacci $n numbers:")
    for (i in 0 until n) {
        print(fibonacci(i).toString() + ", ")
    }
}

fun fibonacci(n: Int): Int {
    return if (n <= 1) {
        n
    } else {
        fibonacci(n - 1) + fibonacci(n - 2)
    }
}