getmango / Mango

Mango is a self-hosted manga server and web reader
https://getmango.app
MIT License
1.72k stars 124 forks source link

Reuse downloader client to help lower network overhead #128

Open Timbus opened 3 years ago

Timbus commented 3 years ago

https://github.com/hkalexling/Mango/blob/df51406638d7266a990bd2b660e3bcc2d2d71c53/src/mangadex/downloader.cr#L142 Should probably reuse a connected client for downloads, which should reduce overhead a tiny amount.

Just hang on to a client using a lazy getter I suppose: https://crystal-lang.org/api/master/HTTP/Client.html#reusing-a-connection

hkalexling commented 3 years ago

Thanks for the suggestion! I am not very familiar with the Crystal compiler internals and the GC but I think the performance improvement would be very minimal if any. But I guess it doesn't hurt to optimize a bit :P Are you interested in submitting a PR to the dev branch?

Timbus commented 3 years ago

Sure thing: https://github.com/hkalexling/Mango/pull/130

Also regarding performance, the problem with reconnecting each time is that you need to allocate a socket, do the TCP handshake, generate new TLS keys, etc etc.. So it's not really related to Crystal's performance (which is excellent, yes), it's mostly network related. Avoiding this overhead is mostly for mangadex's benefit, but it does slightly benefit the client too.