5 ms·
Building a concurrent TCP server with libmill
- deleted 11y ago[deleted]
- wcummings 11y agoCan anyone explain the deadlines vs timeout distinction?
- rumcajz 11y agoTimeout: finish in 10 seconds. Deadline: finish at 7:15:35PM. The advantage of deadlines is that you can define a fixed deadline and then re-use it for any number of calls, without having to subtract the time already spent in previous calls.
- obstinate 11y agoYes, and if you set the deadline on the client, the server knows (subject to its time skew) when the request needs to finish. With a timeout, you have to factor in latency, which is necessarily error prone. Basically, deadline is a context-free timeout.
- huhtenberg 11y ago... unless, of course, it's on the wall clock scale, in which case changing machine time will invalidate all your deadlines. Just need to be careful to use something like 'ticks from the last boot' rather than UTC time.
- obstinate 11y agoIn competently run environments, wall clock changes are smeared. :) there is no way to use ticks since last boot, since the server will have a different value from the client.
- deleted 11y ago[deleted]
- Retr0spectrum 11y agoThis looks very useful. Would this be a good base to make something like a custom HTTP proxy with?
- abcd_f 11y agoIf I understand correctly, this is a framework for non-preemptive cooperative multitasking whereby provided API functions serve as yield points. Pretty much what Windows API was before NT/2000. Not exactly a co-routine library, at least not in a conventional definition of co-routines.
- rumcajz 11y agoYes, that's exactly what it is. But it also matches wikipedia's difinition of coroutine: "Coroutines are computer program components that generalize subroutines for nonpreemptive multitasking, by allowing multiple entry points for suspending and resuming execution at certain locations."
- btrask 11y agoFibers and coroutines are different uses for the same thing. If you schedule your coroutines based on the kernel scheduler, they're fibers. If you jump between fibers explicitly, they're coroutines.
- rumcajz 11y agoUsing that definition, libmill is definitely coroutine-based. It does the scheduling itself.
- btrask 11y agoI think it's mainly a fiber library, actually. The TCP and channel functions yield and resume automatically based on when the underlying operation blocks. They have yield(), but I don't see the opposite, the ability to explicitly resume a stopped context. Edit: for a "pure" coroutine library, I'd recommend libco from BSNES. It only has 4 functions: active, create, switch and delete. I wrote a fiber library using libco plus libuv, which was fairly easy. https://web.archive.org/web/20140209005854/http://byuu.org/programming/libco/ https://web.archive.org/web/20140209005854/http://byuu.org/p... (unfortunately he still hasn't rebuilt his site)
- pantalaimon 11y agoAre the coroutines scheduled across cores or do they all run in the same thread?
- rumcajz 11y agoSame thread.
- jkarneges 11y agoVery cool. Any idea how this compares to lthread?
- culo 11y agoWould be cool to add KONG [1] to libmill to secure and monitor API traffic. [1] https://githu.com/mashape/kong https://githu.com/mashape/kong
- hassy 11y agoThis comment doesn't even make sense. Kong is a cool product, but Kong spam from a couple of accounts [1] on HN is getting tiresome. (Maybe it's just that I look through the comments of most stories to do with APIs.) https://hn.algolia.com/?query=mashape%2Fkong&sort=byPopularity&prefix&page=0&dateRange=pastMonth&type=comment https://hn.algolia.com/?query=mashape%2Fkong&sort=byPopulari...