Live data from Hacker News

Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

github.com

111–119 of 119 posts

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#111
post #23

Considering the latency between the user web browser and the server, does the “extremely low latency on account of caching all files in memory” really matter? The files should already be cached by the OS and using sendfile lets the OS copy the file directly to the network.

Once you add a CDN into the picture, it almost doesn't matter what you use to serve static assets for your web app.

Plus, like you said, 10-20ms extra on top of the actual latency from the server is not going to make any difference to the end user.

There are use cases where you probably need something like Nginx or whatever to handle lots of requests without a CDN but these are rare.

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#112
post #59

Earlier quoted context omitted.

I’m not so sure, if you’re serving massive files this is not perhaps the option you want. If your SPA is so big you can’t handle a container that has its app code and assets in RAM perhaps it’s also too large. I see it as a pragmatic trade off between speed and RAM. Even free tier EC2 instance should have enough RAM to handle pretty much any SPA even if the text content is duplicated (compressed) especially seeing as…

I think the argument is the same for files that fit in memory. This sort of thing is fairly well-trodden (if unsettled, to mix up the metaphors) ground, for yet another take there's varnish and Poul-Henning Kamp's strident writings about it.

For anyone else wanting to read about it: https://varnish-cache.org/docs/trunk/phk/notes.html

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#113
post #111
post #23

Considering the latency between the user web browser and the server, does the “extremely low latency on account of caching all files in memory” really matter? The files should already be cached by the OS and using sendfile lets the OS copy the file directly to the network.

Once you add a CDN into the picture, it almost doesn't matter what you use to serve static assets for your web app. Plus, like you said, 10-20ms extra on top of the actual latency from the server is not going to make any difference to the end user. There are use cases where you probably need something like Nginx or whatever to handle lots of requests without a CDN but these are rare.

I agree on the CDN.

Reading assets from files instead of a RAM cache won’t add “10-20ms”. This is measured in microseconds, not milliseconds. Most servers nowadays are using SSDs or eNVM. And as I wrote earlier, the files are likely already cached in RAM by the OS anyway :)

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#114
post #38
post #33

Earlier quoted context omitted.

Latency between me and my cloud provider is about 10x lower than the latency of Python's http.server on localhost. (It's negated by the SSL handshake, but that's another discussion...)

Is that wall-clock measurement or are you using a tool like Apache Benchmark to see the latency? I ask because those numbers seem really off.

The load time in Chrome Dev Tools

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#115
post #111

Earlier quoted context omitted.

Once you add a CDN into the picture, it almost doesn't matter what you use to serve static assets for your web app. Plus, like you said, 10-20ms extra on top of the actual latency from the server is not going to make any difference to the end user. There are use cases where you probably need something like Nginx or whatever to handle lots of requests without a CDN but these are rare.

I agree on the CDN. Reading assets from files instead of a RAM cache won’t add “10-20ms”. This is measured in microseconds, not milliseconds. Most servers nowadays are using SSDs or eNVM. And as I wrote earlier, the files are likely already cached in RAM by the OS anyway :)

> Reading assets from files instead of a RAM cache won’t add “10-20ms”.

I know. I was just using a hypothetical worst case scenario to exemplify that it doesn't matter.

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#116
post #110

Earlier quoted context omitted.

The article is about serving SPAs. In SPAs the "pages" are not really pages, they are program state. Just because you think /whatever shouldn't go to the homepage doesn't mean your way is the best way for an SPA to work. Maybe I'd rather display the current sale instead of a generic "404" error. Nothing wrong with that. If you're scraping my site or something, then too bad for you. The SPA server is under no obligati…

> Just because you think /whatever shouldn't go to the homepage doesn't mean your way is the best way for an SPA to work. Maybe I'd rather display the current sale instead of a generic "404" error. Nothing wrong with that. I Return a non-200 response doesn't mean you can't return a page. You can indeed display the current sale in the content returned with a 404 response and most sites do. A SPA absolutely can return…

>Otherwise you are directly contributing to making the internet worse.

I don't think it really matters as much as you say it matters. It isn't "making the internet worse", it's only affecting the specific site's indexing, so don't act like this happening is bleeding out to other sites and affecting everyone. Calm down, "the internet" isn't getting worse from this practice.

>A SPA absolutely can return tue full index.html content for every end point, but it shouldn't lie with it's status codes in the process.

That's your opinion. I'm fine with it returning a 200. The thing about SPAs is "the server" doesn't always know if a route is valid or invalid. Hosting an SPA on S3 is one example of that. It responds to requests made to unfound resources with the index page, and a 200 status. It does not know if /account or /config does or does not exist in the front-end routing, the server is dumb and can only serve assets that it knows exist. So it returns the content for the index page and the front-end then decides if the route is valid or not, because the front end state changes with the URL, and there could be thousands or billions of different routes, especially if data is included in the route. There is no way to set up the server to know every route that might happen when it encounters something like /account/verify/8ab2c09f43e7b2a094839ab3cef329

In this case the back end serves index.html with status 200 and the front-end sorts out what to do.

And I'm fine with it, this doesn't "make the internet worse", only the SPA site is affected (if it really has any effect at all).

You can serve pages on your site however you want to, I don't really care what your site does.

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#117

By the way, is there a really minimal, really fast, reasonably secure, zero-cofig single-binary web server which would only support HTTP GET and just expose all the static content in a given directory over it?

Caddy [1] is a single binary. It is not minimal, but the size difference is barely noticeable. serve also comes to mind. If you have node installed, `npx serve .` does exactly that. There are a few go projects that fit your description, none of them very popular, probably because they end up being a 100-line wrapper around http frameworks. [1] https://caddyserver.com/

> It is not minimal, but the size difference is barely noticeable.

Minimality is not about size, it's about reducing the attack surface.

> There are a few go projects that fit your description, none of them very popular, probably because they end up being a 100-line wrapper around http frameworks.

Indeed. Everyone can write their own but dependencies will make its attack surface enormous and performance will probably be mediocre at best.

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#118

Earlier quoted context omitted.

This isn’t really feasible, think about how dynamic routes can be? Can you generate a route for every ID of a thing?

I have actually seen this approach for SSG. You define a function to get all IDs, then the framework renders all of the pages using those.

Well you could plausibly do this with nano-web, simply disable SPA_MODE and generate your routes in this manner.

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#119
post #52

Earlier quoted context omitted.

Not sure what single binary means but here’s my take. https://github.com/dclowd9901/posse

Single binary meaning you only need a single binary to run it, nothing else. Yours is not single binary nor zero config

Helpful, thanks
Post reply on HN