Sunday, April 07

Geek

Daily News Stuff 7 April 2019

Tweetle Beetle Bottle Battle Edition

Tech News

  • My adventures in Crystal land continue so far without the crushing realisation that it all, in fact, sucks.  Uploading binaries sucks because I'm still stuck on ADSL, but I'll get Crystal installed on my dev server shortly to sort that out.

    I wrote a little test app to compare performance of HTTP via the Amber framework, raw HTTP by the bundled server, TCP sockets, UDP sockets, web sockets, and Unix sockets.  Over a Unix socket with a single client and server process on my dev server I can get 50,000 requests per second.  That's mostly consumed by the kernel and not by the app itself, because the packets I'm sending are small and I'm just echoing them back again without any real processing load.

    Despite the fact that Crystal is statically typed and compiled, I can write code like this, compile it and run it without a single warning:

    def handle_client(client)
      while message = client.gets
          client.puts message
      end
    end

    def serve_tcp
      server = TCPServer.new("localhost", 3000)
      while client = server.accept?
        spawn handle_client(client)
      end
    end

    def serve_unix
      server = UNIXServer.new("/tmp/amble.sock")
      while client = server.accept?
        spawn handle_client(client)
      end
    end

    So TCP and Unix socket servers can share the same handler code transparently, and I haven't needed to define the type of anything anywhere.  It could easily be Ruby code, except that it's fast.

    The one notable limitation of Crystal right now is that it's single-threaded.  Python and Ruby are multi-threaded but bound by something called a Global Interpreter Lock (the infamous GIL), which means that only one thread can actually be executing Python or Ruby instructions at any time.  This actually makes things faster because otherwise you have to have locks controlling access to datastructures shared by the threads.

    Crystal (currently) just has one operating system thread (plus a second one for the garbage collector) and uses green threads a.k.a fibers for internal concurrency.  You can see that in the above code - every time a connection comes in to the socket I spawn a new thread.  Fibers only use 4K of RAM each so you can have trillions of them if you want.

    Internally it's using an event loop, but unlike a trainwreck like Node.js you don't care about that.  You spawn your little fibers and get on with your life.  Got 10,000 concurrent connections?  Who cares?  That's 40MB of RAM; it costs about 20¢ per month.  If you even stopped for a minute to think about it you just wasted more money than it is likely to cost you.

    And given that it's ten times faster than Python or Ruby for many tasks, it's like being given a multi-threaded language and a 10-core server for free.  Even so, improved concurrency is at the top of the development roadmap.

    I'm liking Crystal a lot so far, with the caveat that library support is (unsurprisingly) far behind Ruby, let alone Python.  Python has a library for everything.  Except VelocyPack.

    Update: Ooh, a brand new LMDB binding!  LMDB is perfect here because it supports multiple independent processes directly mapping the same database.  I did find a couple of earlier bindings but the projects had been dormant a couple of years while the Crystal language has been updated regularly.

    LMDB is kind of magical.  It's pretty good at handling concurrent writes (it's properly ACIDic), though it doesn't deliver the transaction performance of high-end database engines.  But being memory-mapped and copy-free it is phenomenally fast at reads.  I ran some tests in Python a while back reading 1GB per second on a small VPS.

    With LMDB it doesn't matter that your language has a GIL or uses green threads, because you can just run multiple processes.  It handles transactions and crash recovery for you, the database is a single file, and it comes with a hot backup utility where the backups are themselves LMDB databases.  That is, restore time once you have a backup is zero.

    This makes a project I've wanted to do for years suddenly very, very feasible.

  • TSMC has started risk production of 5nm devices.  (WikiChip Fuse)

    This extends the use of EUV throughout the production process and significantly shrinks the geometry, packing about 80% more transistors per square millimetre.  Performance and power improvements are expected to be smaller, on the order of 
    10%.

  • But MongoDB is web scale.

    A good roundup of terrible trends in web development.

  • Browsers are increasingly disabling disabling click tracking.  (Bleeping Computer)

    Except for Firefox among the major players.  Brave also still allows this, and it's likely that MoonPie and Vivaldi and other niche browsers do too.

    I didn't know that the ping attribute was at thing.  That's really useful and much better than using JavaScript to achieve the same end, but users should be able to turn it off.

  • Does Apple's "Magic Keyboard" still suck?  Yes.  (ZDNet)

Video of the Day



Just wait until he starts explaining how to construct five dimensional polytopes out of four dimensional ones.  He even has a model.


Bonus Video of the Day





Disclaimer: When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle.

Posted by: Pixy Misa at 11:42 PM | Comments (7) | Add Comment | Trackbacks (Suck)
Post contains 880 words, total size 8 kb.

1 "ping attribute"
At some point, Proxomitron-style adblocking will come back into vogue, because it can clip this nonsense right out of the page before the browser even sees it.  I mean, "remove an attribute from a tag" is, like, top dead center of Proxomitron's wheelhouse.

Posted by: Rick C at Monday, April 08 2019 02:54 AM (Iwkd4)

2 Yes, that's exactly why the ping attribute is so much better than JavaScript.  It's easy and consistent for developers building websites, and it's easy and consistent for developers building privacy filters.

Let's say you have a tech blog and you just want to know how many people click the links in your daily posts so you can see what's popular.  Ping attribute.  And if you don't want sites doing that, just strip the ping attribute in your proxy.

Posted by: Pixy Misa at Monday, April 08 2019 04:05 AM (PiXy!)

3 What are you actually doing with all these languages you try out?

Posted by: Mauser at Monday, April 08 2019 10:12 AM (Ix1l6)

4 Every tool,

every favor,

every data bit

that ends up in his list of kit

is one more tool in his fearsome mitt

to try and take over the world.

Posted by: The Brickmuppet at Monday, April 08 2019 11:59 AM (xOgT9)

5 Mauser, mostly what I do is try a language, find a flaw that prevents me from using it (or find that it's a complete pile of crap), and either leave it to return to later or try to scrub it from my brain.


I've been programming mostly in Python for ten or twelve years, and this is the first of all the languages I've looked at that seems to be genuinely better for getting work done.  Mainly because it's just as expressive and much much faster.

Posted by: Pixy Misa at Monday, April 08 2019 02:07 PM (PiXy!)

6 I guess what I'm asking is what is the work you're trying to do?

Posted by: Mauser at Tuesday, April 09 2019 01:14 PM (Ix1l6)

7 Current projects include:
  1. Blog platform updates.
  2. Centralised social network.
  3. Distributed social network.
  4. Multi-mode database (something half-way between Redis and MongoDB).
  5. Load-balancing web proxy/cache/filter/router/API gateway.
  6. Predictive performance monitor (something that says "in six months at current growth your peak period load will max out these three servers)

And that's before the stuff I do for my day job, which would also benefit enormously from a faster language.


The performance monitor needed a statically-compiled portable binary for its data collector, which is why I've been looking at compiled languages just recently.


The database has an implementation in Python, but while it's reasonably fast as a pure KV store, once you turn on indexing the performance plummets due to bottlenecks generating the key values in Python.  I just couldn't resolve that and had to set it aside.  Crystal is fast enough that it's not an issue, while not really being any harder to program in than Python.

That was why I was excited to see a new LMDB library for Crystal - LMDB is the embedded database library I was using with Python, and it has exactly the feature set I need.  So that project that got put on the shelf three or four years ago will likely see at least an alpha release by the end of next month.  It's easy, and the feature set is unique, it's just that my Python implementation wasn't fast enough to be useful.

Posted by: Pixy Misa at Tuesday, April 09 2019 11:40 PM (PiXy!)

Hide Comments | Add Comment




Apple pies are delicious. But never mind apple pies. What colour is a green orange?




59kb generated in CPU 0.0176, elapsed 0.1113 seconds.
58 queries taking 0.0987 seconds, 347 records returned.
Powered by Minx 1.1.6c-pink.