Trying to further improve #swad, and as I'm still unhappy with the amount of memory needed ....

Well, this little and special custom #allocator (only dealing with equally sized objects on a single thread and actively preventing #fragmentation) reduces the resident set in my tests by 5 to 10 MiB, compared to "pooling" with linked lists in whatever #FreeBSD's #jemalloc serves me. At least something. 🙈

https://github.com/Zirias/poser/blob/master/src/lib/core/objectpool.c

The resident set now stabilizes at 79MiB after many runs of my somewhat heavy jmeter test simulating 1000 distinct clients.

poser/src/lib/core/objectpool.c at master · Zirias/poser

POsix SERvices framework for C. Contribute to Zirias/poser development by creating an account on GitHub.

GitHub
@zirias 👋 I would love to use a package of #swad

Related question, only for people who *have* some need for either authentication or proof-of-work added to their #nginx:

Would you consider #swad if there was a pre-built #package (or port) for your OS? IOW, is building and installing it manually from source an issue?

Please help me spread the link to #swad 😎

https://github.com/Zirias/swad

I really need some users by now, for those two reasons:

* I'm at a point where I fully covered my own needs (the reasons I started coding this), and getting some users is the only way to learn about what other people might need
* The complexity "exploded" after supporting so many OS-specific APIs (like #kqueue, #epoll, #eventfd, #signalfd, #timerfd, #eventports) and several #lockfree implementations based on #atomics while still providing fallbacks for everything that *should* work on any #POSIX systems ... I'm definitely unable at this point to think of every possible edge case and test it. If there are #bugs left (which is somewhat likely), I really need people reporting these to me

Thanks! 🙃

GitHub - Zirias/swad: Simple Web Authentication Daemon

Simple Web Authentication Daemon. Contribute to Zirias/swad development by creating an account on GitHub.

GitHub

Just released: #swad 0.12 🥂

swad is the "Simple Web Authentication Daemon". It basically offers adding form + #cookie #authentication to your reverse proxy (designed for and tested with #nginx "auth_request"). I created it mainly to defend against #malicious_bots, so among other credential checker modules for "real" logins, it offers a proof-of-work mechanism for guest logins doing the same #crypto #challenge known from #Anubis.

swad is written in pure #C with minimal dependencies (#zlib, #OpenSSL or compatible, and optionally #PAM), and designed to work on any #POSIX system. It compiles to a small binary (200 - 300 kiB depending on compiler and target platform).

This release brings (among a few bugfixes) improvements to make swad fit for "heavy load" scenarios: There's a new option to balance the load across multiple service worker threads, so all cores can be fully utilized if necessary, and it now keeps lots of transient objects in pools for reuse, which helps to avoid memory fragmentation and ultimately results in lower overall memory consumption.

Read more about it, download the .tar.xz, build and install it .... here:

https://github.com/Zirias/swad

GitHub - Zirias/swad: Simple Web Authentication Daemon

Simple Web Authentication Daemon. Contribute to Zirias/swad development by creating an account on GitHub.

GitHub

The release of #swad 0.12 is currently delayed for #github #mfa shenanigans.

As I switched to a new mobile phone, I had to reconnect a new "authenticator app" for #otp to the github account (which I could do on a machine that still had a valid session). Now, on the machine I need for uploading the release, github just doesn't accept the generated codes.😡

I'm seriously considering #selfhosting a #git web frontend. #forgejo comes to mind, should be simple enough. But providing #CI pipelines might be a different beast ... 🤔

Decided to look into the thread "fairness issue" before releasing, and came up with this:

https://github.com/Zirias/poser/commit/a82d10420a2e00c8e539d5d1337d2d6bf736c702

I'm actually amazed by the result, didn't expect that:

* The imbalance with one "loser" thread getting a lot more to do is completely gone
* Overall RAM consumption is significantly lower (which makes sense as the per-thread pools holding currently unused "Connection" objects are now balanced as well). Practical result: 88MiB resident set after 1000 simulated clients firing a total of 8 million requests ... twice!
* Throughput got even better, I can now achieve almost 40k req/s (of course only with TLS, name resolving and informative logging all disabled)
* Response times are sanely distributed around very low averages, like less than 25 ms

Ok, about time to prepare the #swad 0.12 release 😎

#C #coding

Server: Add simple load balancing · Zirias/poser@a82d104

When distributing accepted connections to service worker threads, replace the dumb round-robin by a simple load-balancing algorithm: For each thread, maintain a counter of currently opened connect...

GitHub

Today, it's exactly one month since I released #swad 0.11. And I'm slowly closing in on releasing 0.12.

The change to a "multi #reactor" design was massive. It pays off though. On the hardware that could reach a throughput of roughly 1000 requests per second, I can now support over 3000 r/s, and when disabling #TLS, 10 times as much. Most of the time, I spent with "detective work" to find the causes for a variety of crashes, and now I'm quite confident I found them all, at least on #FreeBSD with default options. As 0.11 still has a bug affecting for example the #epoll backend on #Linux, expect to see swad 0.12 released very very soon.

I'm still not perfectly happy with RAM consumption (although that could also be improved by explicitly NOT releasing some objects and reusing them instead), and there are other things that could be improved in the future, e.g. experiment with how to distribute incoming connections to the worker threads, so there's not one "loser" that always gets slowed down massively by all the others. Or design and implement alternative #JWT #signature algorithms besides #HS256 which could enable horizontal scaling via load balancing. Etc. But I think the improvements for now are enough for a release. 😉

Analyzed and THIS is the core part of the fix:

https://github.com/Zirias/poser/commit/b1aa9784955db4712d695d217344cb65bbff6ed6

I'll have to revisit that later, it's probably wasteful as it is right now, I should come up with some better idea to implement async logging later. But it DOES fix the bug I finally identified that could make #swad crash.

Now, just running it, observing it, stress-testing it from time to time ... wish me luck that THIS was indeed the only reason left for crashing in "normal operation".

I already know there's more work to do regarding reload (SIGHUP) with the multi-threaded approach, it's currently unsafe unfortunately, must be fixed before the next release.

Log: Fix async logging with service workers · Zirias/poser@b1aa978

Fix async logging with multiple service workers. Enqueueing a thread job from within a pool thread is not safe any more, because the job must know its "owning" service worker thread. So, ...

GitHub

Oh boy, I have a lead! And it's NOT related to #TLS. I finally noticed another pattern: #swad only #crashed when running as a #daemon. The daemonizing wasn't the problem, but the default logging configuration attached to it: "fake async", by letting a #threadpool job do the logging.

Forcing THAT even when running in foreground, I can finally reproduce a crash. And I wouldn't be surprised if that was actually the reason for crashing "pretty quickly" with #LibreSSL (and only rarely with #OpenSSL), I mean, something going rogue in your address space can have the weirdest effects.