Ktor relies on Async Servlets at the moment - which as of June, is literally the only thing stopping it working on Google App Engine Standard. See: https://cloud.google.com/appengine/docs/standard/java/release-notes#june_28_2017
As you're using Coroutines, is it necessary to use AsyncServlets? Or could I simply fork the http-servlet module and remove the async call?
The only way to get it work in sync mode is to use blocking coroutine dispatcher and somehow run everything on it. Not sure if it is possible to support all the stuff in single-threaded environment.
At least async channels couldn't be implemented on top of blocking ServletInputStream/ServletOutputStream (attempting to do so will cause deadlock)
On the other hand we can use ThreadManager to launch new theads to workaround it. However it could have performance penalty. Need to be designed carefully.
Would be nice to make it possible, there is a significant cost difference between AppEngineStandard/Beanstalk over running flex/containers.
I haven't done enough with Coroutines yet, I think everything still can be async, just that you would have to wait for a response from the execute method?
Don't call:
val asyncContext = request.startAsync().apply { timeout = 0L }
Then do a blocking call to:
hostPipeline.execute(call)
Although I'm guessing I'm missing something if it was that easy?
No, unfortunately it is not going to work so easy. It could only work in some simple cases. Of course Servlet/Read/WriteChannels need to be rewritten to do blocking (that could cause deadlocks as blocking stops all call-related coroutines). Also respondWrite { } could cause issues. For sure websockets will not work at all. So the only hope is ThreadManager
For sure we should collect neither response nor request body as it could be too huge.
call.respondWrite {
val ch = call.receive<ReadChannel>()
while (true) {
val something = TODO("read something from channel ch") ?: break
append(something)
}
}
Another example
withTimeout(...) {
call.respond(....)
}
will never fail with timeout as all coroutines could get stuck
OK, looks like this will be a massive pain. Or will be really hacky. There is a feature request open with Google, but knowing how these things go... will be a while before that ever happens: https://issuetracker.google.com/issues/65104189
They are already using jetty so I wonder why AppEngine doesn't support async servlets.
I saw that you added support for blocking servlets in 0.9.1. Does that mean that we can run non async serverlets?
I saw blocking servlet support in 0.9.1 does that mean I can use this with a non-async servlet now?
@chrisjenx Yes, now ktor can run in servlet-containers with no async support such as GAE
@chrisjenx You have a sample for GAE here: https://github.com/ktorio/ktor-samples/tree/master/deployment/google-appengine-standard
Awesome, yeah I got this working last night. Awesome work! I really
appreciate this effort!
I'll buy you a beer at kotlin conf if you're around!
I'll close this out.
On Fri, 18 May 2018, 06:16 Carlos Ballesteros Velasco, <
[email protected]> wrote:
@chrisjenx https://github.com/chrisjenx You have a sample for GAE here:
https://github.com/ktorio/ktor-samples/tree/master/deployment/google-appengine-standard—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ktorio/ktor/issues/219#issuecomment-390188522, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABHRsa9xdhAz_QGE6dZhPpwfKflCf89Eks5tzruhgaJpZM4P8VPc
.
Most helpful comment
@chrisjenx You have a sample for GAE here: https://github.com/ktorio/ktor-samples/tree/master/deployment/google-appengine-standard