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

usleep degrades when using Swifter #521

Open
monkekode opened this issue May 12, 2022 · 0 comments
Open

usleep degrades when using Swifter #521

monkekode opened this issue May 12, 2022 · 0 comments

Comments

@monkekode
Copy link

I have the following server:

import SwiftUI
import Swifter

@main
struct MacInputServer: App {
    let server: HttpServer;

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }

    func sleep(req: HttpRequest) -> HttpResponse {
        usleep(100_000);
        return .ok(.text(""))
    }

    init() {
        server = HttpServer()
        server["/sleep"] = sleep
        try! server.start(999, forceIPv4: true, priority: DispatchQoS.QoSClass.userInteractive);
    }
}

I'm running while true; do time curl localhost:999/sleep; done to test it. The first ~100 requests finish in about 120ms as expected. But after that it starts hanging for up to 10 seconds:

curl localhost:999/sleep  0.01s user 0.01s system 11% cpu 0.118 total
curl localhost:999/sleep  0.01s user 0.01s system 0% cpu 10.121 total
curl localhost:999/sleep  0.01s user 0.01s system 0% cpu 5.134 total
curl localhost:999/sleep  0.00s user 0.01s system 0% cpu 5.902 total

If I just sleep in a loop, the performance stays consistent, so this is definitely the fault of Swifter. How can this be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant