Live data from Hacker News

Using Flat Files So Elections Don’t Break Your Server

open.blogs.nytimes.com

41–50 of 51 posts

Re: Using Flat Files So Elections Don’t Break Your Server

#41
post #37

Earlier quoted context omitted.

All righty... it was just a usage of the term "flat file" I was unfamiliar with. :-)

Yeah, I think they made that up. I've only ever encountered the term "flat file" in the sense of a flat file database, such as a CSV file. As you say, pre-rendered static page is a much better name for it.

I have always used the term "static html" (as opposed to "dynamically generated html").

"Flattened files" may have been what they were meaning. "Flattened Files" would be a nice simple term for them if there wasn't confusion with Flat-file databases.

Re: Using Flat Files So Elections Don’t Break Your Server

#42
post #12

the filesystem is just another datastore. using it like this means you're spreading out the requests per second across each individual server's available IO, however you've also forsaken the "getting data from point a to point b" features of other datastores and therefore have to do it yourself (usually rsync). to be honest, since there wasn't actually a problem to solve as varnish is setup as both an HA environment…

The file-system isn't just another data-store: it's I/O and therefore special. On systems with 'sendfile' data can be sent straight from disk to network port without CPU time (and any copies being made). This is used extensively by high-performance webservers and web-accelerators.

Re: Using Flat Files So Elections Don’t Break Your Server

#43

Ugh. They're not talking about Flat Files. They're talking about HTML. Saying so in the headline would have saved a lot of confusion. A flat file is essentially a .csv holding data, and can be a fast way to bulk load denormalized data. As such, it actually does have a use in the context of scaling, so it's natural to expect that they were using the term correctly. A static file, or more simple, a HTML file is what th…

> A static file, or more simple, a HTML file is what they're actually talking about.

Static yes, HTML no, an HTML file could still have e.g. SSI instructions. It's valid HTML, but if the webserver supports SSI it's not going to be static.

Re: Using Flat Files So Elections Don’t Break Your Server

#44
post #11

I may sound naive here, but: if all you're doing is serving just 184 flat files, then why do you need all this RoR jazz? Can't a bunch of Apache/Nginx servers behind a load balancer (Varnish, TrafficServer, etc.) handle that just fine? Throw in a DNS-based scheme for failover/redundancy?

> I may sound naive here, but: if all you're doing is serving just 184 flat files, then why do you need all this RoR jazz?

Generate the static files: those files contained live election results, so they had to be regenerated as new results came in.

Re: Using Flat Files So Elections Don’t Break Your Server

#45

Ugh. They're not talking about Flat Files. They're talking about HTML. Saying so in the headline would have saved a lot of confusion. A flat file is essentially a .csv holding data, and can be a fast way to bulk load denormalized data. As such, it actually does have a use in the context of scaling, so it's natural to expect that they were using the term correctly. A static file, or more simple, a HTML file is what th…

> A static file, or more simple, a HTML file is what they're actually talking about. Static yes, HTML no, an HTML file could still have e.g. SSI instructions. It's valid HTML, but if the webserver supports SSI it's not going to be static.

Well, now we're arguing semantics, but no... an SSI instruction is not part of HTML. It's a server-side scripting language. I could set up my server to interpret PHP embedded in .html files as well, but then they're not really HTML files any more.

Re: Using Flat Files So Elections Don’t Break Your Server

#47
post #6
post #3

It's nice to see detail like this on high-traffic, high-risk environments. I'm curious about their provisions for cross-datacenter failover. The article mentions haproxy being ready to direct requests to a different datacenter as well as ELB spanning availability zones. I'd expect a failover option entirely outside AWS as well, with short-TTL DNS ready to make the switch. I'm also not sure what value varnish brings t…

Doesn't Varnish handle many times more concurrent clients than apache does, at significantly lower system load? It could just be pure optimization.

It is pure optimization - they said it gives them a performance boost and smooths things out.

In their "flat-file" setup though - they are deliberately configured so that, should varnish fail (which was one of their concerns) - they don't actually need it - they could just have haproxy immediateley start hitting the apache servers directly.

Re: Using Flat Files So Elections Don’t Break Your Server

#48
post #42
post #12

the filesystem is just another datastore. using it like this means you're spreading out the requests per second across each individual server's available IO, however you've also forsaken the "getting data from point a to point b" features of other datastores and therefore have to do it yourself (usually rsync). to be honest, since there wasn't actually a problem to solve as varnish is setup as both an HA environment…

The file-system isn't just another data-store: it's I/O and therefore special. On systems with 'sendfile' data can be sent straight from disk to network port without CPU time (and any copies being made). This is used extensively by high-performance webservers and web-accelerators.

sendfile() still requires CPU time - it just passes the job of sending the data over the socket to the kernel to finish up. The previous method would have been a select() loop or similar that ensured the data was sent out to the kernel, involving a bunch of system calls and context swtiches. sendfile lets you hand the job off 100% to the kernel and have your thread move on.

Re: Using Flat Files So Elections Don’t Break Your Server

#49
post #41

Earlier quoted context omitted.

Yeah, I think they made that up. I've only ever encountered the term "flat file" in the sense of a flat file database, such as a CSV file. As you say, pre-rendered static page is a much better name for it.

I have always used the term "static html" (as opposed to "dynamically generated html"). "Flattened files" may have been what they were meaning. "Flattened Files" would be a nice simple term for them if there wasn't confusion with Flat-file databases.

Ah! Now it makes more sense, etymology-wise and all that.

Re: Using Flat Files So Elections Don’t Break Your Server

#50
post #48
post #42

Earlier quoted context omitted.

The file-system isn't just another data-store: it's I/O and therefore special. On systems with 'sendfile' data can be sent straight from disk to network port without CPU time (and any copies being made). This is used extensively by high-performance webservers and web-accelerators.

sendfile() still requires CPU time - it just passes the job of sending the data over the socket to the kernel to finish up. The previous method would have been a select() loop or similar that ensured the data was sent out to the kernel, involving a bunch of system calls and context swtiches. sendfile lets you hand the job off 100% to the kernel and have your thread move on.

I was under the (possibly mistaken) impression that Direct Memory Access (DMA) hardware could move data straight from the Disk Cache to the Network card without touching the CPU Caches at all.
Post reply on HN