ktor icon indicating copy to clipboard operation
ktor copied to clipboard

Kotlin Native Support

Open DanTsk opened this issue 5 years ago • 35 comments

Hello ! Does Ktor support Kotlin Native for now (using Netty)? I saw few comments in JetBrains Blog, but can't find any detailed information about it. Thank you !

DanTsk avatar Sep 08 '18 01:09 DanTsk

Right now, only the HTTP Client supports Kotlin/Native

soywiz avatar Sep 10 '18 10:09 soywiz

Right now, the HTTP client supports osx, and macos. I read Linux is being considered. But windows isn't mentioned anywhere... Is there any plans to support windows? I am building a cross-platform desktop program that targets macos and windows, and just want to know if I can expect windows to be supported in the future. I would rather not waste my time using ktor's http client if windows support is not in the plans.

luca992 avatar Sep 21 '18 20:09 luca992

Can the 'ktor-client-core' be published for other native targets? So at least, custom client engines can be made.

Dominaezzz avatar Oct 19 '18 16:10 Dominaezzz

Any updates on it? Can we now create ktor server-side app for native ?
I found Kotlin Native server - source

DanTsk avatar Mar 02 '19 16:03 DanTsk

@e5l Hey, just saw that this issue was added to 1.1.5 milestone that is closed. Does it mean that Ktor support Kotlin Native? (as the current version is 1.2.0)

DanTsk avatar May 15 '19 16:05 DanTsk

Hi there :) I'm in love with Kotlin Multiplatform! But Ktor server support is blocking for us to use it in our company's product. Is it something that is still planned or this is something that appears impossible in the end ?

I can (try to) give an hand on this, is this possible to have an overview of what is missing or what are the problematics ? Thanks! :)

cflorion avatar Nov 20 '19 15:11 cflorion

ktor server MPP is planned for 1.4.0

cy6erGn0m avatar Dec 05 '19 12:12 cy6erGn0m

Still waiting on MPP websockets :crossed_fingers:

serebit avatar Dec 10 '19 16:12 serebit

and http3 =)

jershell avatar Dec 10 '19 18:12 jershell

Ktor Client is available for linuxX64 but not for the other Linux targets (linuxArm32Hfp, linuxArm64 etc) :( .

napperley avatar Jan 25 '20 04:01 napperley

This would make for a very interesting serverless implementation in combination with things like openfaas or rio.io

krishofmans avatar Feb 17 '20 19:02 krishofmans

I think this issue doesn't receive the attention it is worth. If it was really possible to decouple ktor-server and its modules from Java, it would be groundbreaking. The biggest problem with Java web frameworks is their slow startup time, because the JVM often takes seconds to start up. If K/N ktor-server would be a thing, I am pretty sure that many developers would consider porting existing Kotlin projects that depend on http4k, Spring, Vert.x or similar to ktor which would give them a dramatic performance boost. I don't believe that this issue will be easily resolved (and I am genuinely curious how you guys will tackle it!), so I was a bit surprised to see so little discussion in this thread. I couldn't find a public roadmap, so one can only hope that 1.4 will be around, soon, but until then, the next generation of Kotlin microservices will be waiting 🚀

julKali avatar Feb 26 '20 20:02 julKali

If Ktor Server was ported to Kotlin Native (supporting the linux targets) would Ktor be suitable for Serverless via OpenFaaS? What would the performance footprint for Ktor Server look like on Kotlin Native compared to Go lang?

Currently there isn't a single cloud provider (eg AWS) that provides Kotlin Native support. Having Ktor Server ported to Kotlin Native would help change that. Many cloud providers except for GCP (Google Cloud Platform) are paying lip service to Kotlin support (aka examples/demos are presented but no official Kotlin support is provided). GCP Kotlin support is restricted to Kotlin JVM only, and doesn't extend to Kotlin Native unless Google have some future plans to extend Kotlin support.

napperley avatar Feb 27 '20 22:02 napperley

@napperley at the moment, K/N has poor performance as the dev team primarily focused on compatibility. It will take a few iterations until it is comparable to the more mature Go let alone C. In the meantime, though, it would be great to start with the porting of ktor so that when K/N is performant, ktor is ready to be used.

julKali avatar Feb 28 '20 08:02 julKali

I also think there's a lot of opportunity for kotlin native/ktor in the serverless space and to compete with things like graalvm.

I get that graalvm has different promises than kotlin native as it will transpile more jvm related stuff to native. But still it seems very painful, slow and complex, and also requires changes in the jvm related frameworks.

Offering the combination of native performance/memory usage, ktor and a familiar language might be able to pull over a lot of developers out of the jvm/graalvm space.

krishofmans avatar Feb 28 '20 08:02 krishofmans

@krishofmans exactly! I am currently working with Micronaut because it's specifically made to be compiled as Graal native-image and it's extremely tedious! Documentation is terrible, I have to look up source code in order to find out how to implement simple features, IDEA needs additional configuration (which in part is nowhere documented, I had to figure it out by trial and error) and although they have some support for Kotlin it feels very clunky and requires some hacks. Compiling the Micronaut code then takes forever (especially annoying when testing) and creating Graal's native-image takes even longer (literally minutes). On top of that, it fails every second time with some unidentifiable error (I don't want to bash native-image too much though, as it's currently Early Adopter so errors are to be expected). And another reason why K/N is so valuable: Because Graal's native-image is currently Early Adopter. I suspect Oracle to make it an enterprise feature when it's released. Sorry for the rant, but I really want to stress that for serverless developers, it would be so mind-boggling to have the beauty of Kotlin and the performance of native code - all without the need of weird hacks.

julKali avatar Feb 28 '20 08:02 julKali

I just realized that because ktor seems to rely on reflection a lot, porting it will require significant changes of the whole application pipeline. K/N currently supports reflection only to a very limited extent.

julKali avatar Feb 28 '20 08:02 julKali

Perhaps that's just an opportunity for K/N to also further it's features. Since reflection is basically a metadatamodel of the code that can be modified at runtime.

It could be seen as an api around method/field lookup tables with some additional metadata and perhaps it will become more widely supported in K/N this way.

I know that it's a lot more complex and a lot of work will go into it to support it, but still looks like something that could be worth it if it would also enable porting over other jvm kotlin based frameworks over to the native space.

krishofmans avatar Mar 01 '20 09:03 krishofmans

Is there another issue or PR for this? Still planned for 1.4?

PatrickZGW avatar Apr 21 '20 08:04 PatrickZGW

WIP in e5l/cio-common. Yep, the implementation is in progress.

e5l avatar Apr 21 '20 10:04 e5l

Is the WIP referring to the Ktor Server implementation?

On Tue, 21 Apr 2020 at 22:38, Leonid Stashevsky [email protected] wrote:

WIP in e5l/cio-common. Yep, the implementation is in progress.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ktorio/ktor/issues/571#issuecomment-617098475, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA272Z2HMXMNJBPP5YSPB6DRNVZRHANCNFSM4FT6VNBA .

napperley avatar Apr 22 '20 03:04 napperley

I am not in a hurry, I want to use native servers for a testing framework for iOS and Android I am working on. I have a solution working with okhttp mocks and Objective-C server, under one interface in Kotlin MP. Just interested if there is a way, or some rough ETA, where I could switch that to Ktor Server on Kotlin MP. I would be happy to help, if possible, if there are parts I could comprehend ;)

michallaskowski avatar Apr 29 '20 18:04 michallaskowski

I'm looking forward to this. I'm in a state of changing my tech stack and kotlin is one of them (I want to leave from JVM, golang is another selection). But for me, still kotlin with spring boot apps is the way until a native approach arises. Trying graalvm native support with spring was a failing step. If ktor manages to be native, for sure this will be the way to go for kotlin APIs into docker from scratch.

gentunian avatar May 01 '20 00:05 gentunian

Is there any updates ? (or news)

mahdisml avatar Jun 28 '20 20:06 mahdisml

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

oleg-larshin avatar Aug 10 '20 15:08 oleg-larshin

I have ktor server with cio working as a native image - I posted this YT issue https://youtrack.jetbrains.com/issue/KTOR-965

emrul avatar Jan 10 '21 20:01 emrul

But this won't help if you want to use Ktor server on your iOS app.

Xaseron avatar Jan 11 '21 09:01 Xaseron

According to release notes it is in 2.0.0-beta-1. I tried to test it on Android with CIO server and there is just no response from server when i try to call it. Same issue with Netty on 2.0.0-beta-1 but Netty 1.6.7 works.

With CIO i get no visible errors in output. On Netty there seem to be some issues: No implementation found for int io.netty.channel.kqueue.Native.sizeofKEvent() (tried Java_io_netty_channel_kqueue_Native_sizeofKEvent and Java_io_netty_channel_kqueue_Native_sizeofKEvent__) No implementation found for int io.netty.channel.epoll.Native.offsetofEpollData() (tried Java_io_netty_channel_epoll_Native_offsetofEpollData and Java_io_netty_channel_epoll_Native_offsetofEpollData__) WARN io.netty.util.internal.MacAddressUtil - Failed to find a usable hardware address from the network interfaces; using random bytes:

Nailik avatar Mar 13 '22 02:03 Nailik

@Nailik I think this issue has been fixed https://youtrack.jetbrains.com/issue/KTOR-3653

saket avatar Mar 14 '22 01:03 saket

I think this isn't fixed until I can create native Windows server. The documentation doesn't give any hint why Windows target support is dropped. Can't we take the io.ktor:ktor-server-cio or io.ktor:ktor-server-core as a base. It sounds weird that it's impossible to create server on Windows nowadays. How they can achieve that on ISS or .Net Core?

jpink avatar Sep 22 '23 13:09 jpink