Live data from Hacker News

Serving a high-performance blog solely from memory, using Rust

xeiaso.net

131–140 of 143 posts

Re: Serving a high-performance blog solely from memory, using Rust

#132

I want to see this taken to the logical extreme. A real OS with actual drivers (no unikernel, no virtio) for a small set of hardware that only serves static pages. No need for virtual memory. Just hardcode the blog posts right into the OS and use the most minimal TCP stack you can make.

> No need for virtual memory.

If it's amd64, long mode requires a page table. Otherwise, a page table is handy so you can get page faults for null pointer dereferencing. Of course, you could do that only for development, and let production run without a page table.

My hobby OS can almost fill your needs though, but the TCP stack isn't really good enough yet (I'm pretty sure I haven't fixed retransmits after I broke them, no selective ack, probably icmp path mtu discovery is broken, certainly no path mtu blackhole detection, ipv4 only, etc), and I only support one realtek nic, cause it's what I could put in my test machine. Performance probably isn't great, but it's not far enough along to make a fair test.

Re: Serving a high-performance blog solely from memory, using Rust

#133

Earlier quoted context omitted.

> Even though your disk read is a memory read in all likelihood given how filesystem caching works, it's still an IO call, which isn't free. I wonder if io_uring could be used to issue a single syscall that would read data from disk (actually using page cache) and send it on the network. Of course, you could use DPDK or similar technologies to do the opposite - read the data from disk once and keep it in user-space b…

> I wonder if io_uring could be used to issue a single syscall that would read data from disk (actually using page cache) and send it on the network. Only if you don't care about HTTP/2 and TLS. And if you don't care about those, you can as well do sendfile() from a thread.

You can do kernel TLS for sendfile at least, maybe for io_uring too? Probably not for HTTP/2, but I'm not convinced multiplexed tcp in tcp is a good protocol for the public internet anyway.

Re: Serving a high-performance blog solely from memory, using Rust

#134
post #133

Earlier quoted context omitted.

> I wonder if io_uring could be used to issue a single syscall that would read data from disk (actually using page cache) and send it on the network. Only if you don't care about HTTP/2 and TLS. And if you don't care about those, you can as well do sendfile() from a thread.

You can do kernel TLS for sendfile at least, maybe for io_uring too? Probably not for HTTP/2, but I'm not convinced multiplexed tcp in tcp is a good protocol for the public internet anyway.

That's indeed possible, if one has a TLS stack which supports KTLS. I however don't think there's not too many of those yet, and probably even less so in Rust where both the library and a potential Rust wrapper would need to support it.

Re: Serving a high-performance blog solely from memory, using Rust

#135
post #20

Earlier quoted context omitted.

That “traditional” site doesn’t actually load the data from disk, in practice. It does once, after a reboot, but that’s true for this solution’s executable file as well.

That “traditional” site doesn’t actually load the data from disk, in practice. It does once, after a reboot, but that’s true for this solution’s executable file as well. Does Apache/Nginx/IIS load static files in memory ahead of time? I would assume no, unless someone went through and did some optimizations. Even so, there is always a point where memory runs out, and in that case a templating engine is essentially co…

They don't, but OS can pre-fetch files ahead of time. Zfs will load "hot" files as soon as it can.

You can also easily preload things into memory in boot yourself, so static websites usually don't serve files from disk.

Re: Serving a high-performance blog solely from memory, using Rust

#136
post #29

Earlier quoted context omitted.

The trick is to do lots of little changes that are easy to do in isolation. Then do bigger changes later after you learn what you messed up. I have CDO too but I work around it by sheer trolling with infrastructure, like my hacked up to hell CDN: https://xeiaso.net/blog/xedn

Relentless Refactoring is a great tool, but one that is often stymied by faddish behaviors like micro-services/modules. Small projects tend not to have that problem and so make a better petri dish. Of course then you have to take your knowledge out of the 'lab' and apply it in vivo... A lot of our (and in particular, my) best features come from of relocating the boundaries between things, to make space for features t…

I love the idea of "relentless refactoring"

Re: Serving a high-performance blog solely from memory, using Rust

#138
post #101

Earlier quoted context omitted.

I think what you’re saying is that if OP were to test your site from Helsinki they would see the server speed you’re talking about. Is that right?

Yeah, unless I can find a CDN to cache my blog (and maybe its static assets) that would be affordable enough for my needs.

I wrote an article about making server-side rendered sites fast around the world without a CDN at https://fly.io/ruby-dispatch/semi-static-websites/

My examples are in Ruby, which is super slow compared to what you’re doing. Now I’m super curious what kind of performance you’d get globally on Fly if you deployed to a bunch of different regions.

Re: Serving a high-performance blog solely from memory, using Rust

#139
post #101

Earlier quoted context omitted.

Yeah, unless I can find a CDN to cache my blog (and maybe its static assets) that would be affordable enough for my needs.

I wrote an article about making server-side rendered sites fast around the world without a CDN at https://fly.io/ruby-dispatch/semi-static-websites/ My examples are in Ruby, which is super slow compared to what you’re doing. Now I’m super curious what kind of performance you’d get globally on Fly if you deployed to a bunch of different regions.

If you can help me get a Nix flake running on Fly, I'll try it!

Re: Serving a high-performance blog solely from memory, using Rust

#140
post #139

Earlier quoted context omitted.

I wrote an article about making server-side rendered sites fast around the world without a CDN at https://fly.io/ruby-dispatch/semi-static-websites/ My examples are in Ruby, which is super slow compared to what you’re doing. Now I’m super curious what kind of performance you’d get globally on Fly if you deployed to a bunch of different regions.

If you can help me get a Nix flake running on Fly, I'll try it!

I know next to nothing about Nix at Fly except there's a few folks who are looking at it at Fly. The repo at https://github.com/fly-apps/nix-base shows how its working for a Rails app. Is that enough to get you running with Nix flakes?

Beyond that https://community.fly.io is the best place to get help with Nix on Fly since my abilities are exceeded. There's a Rust thread at https://community.fly.io/t/running-reproducible-rust-a-fly-a... that touches on nix flakes.

Post reply on HN