weblink icon indicating copy to clipboard operation
weblink copied to clipboard

Exploratory: Run libuv loop on a background thread

Open Frixuu opened this issue 1 year ago • 0 comments

This implementation creates two threads:

  • Thread A runs the libuv loop in the Default mode (so it does not saturate the CPU).
    • On an incoming TCP connection, thread A's event loop is ticked on thread A.
    • This is because AFAIK libuv is not thread-safe, but arbitrary events/timers can do work on libuv handles.
  • Thread B runs a regular haxe.Timer.
    • On timer interval, a blocking TCP socket is being opened, connected to the server, and immediately closed.
    • This is so A's events are being run even if the Weblink server has no traffic.

There are a couple of reasons why not to merge it: it bumps Haxe version to 4.3.0 to use sys.thread.Condition, it breaks apps that depend on app.server.update, it slightly sabotages the Node.js port attempts, (edit: it craps itself on Windows), but most importantly:

It requires Hashlink nightly (or 1.15+ when/if that releases).

I'm too lazy to do a bisect right now, but running the server on HL 1.14.0 has a very high chance to hang somewhere inside hl_gc_alloc_gen. That seems to be fixed (possibly in 664/d82c3c), but not included in a tagged release.

Frixuu avatar Sep 29 '24 20:09 Frixuu