4 ms·
Ummm... because it’s an O(1) array lookup not a search at all? Infuriating. It’s read-only static data. Spending even 60ms on the response is ridiculous. Readi
by zaroth 9y ago
Ummm... because it’s an O(1) array lookup not a search at all? Infuriating.
It’s read-only static data. Spending even 60ms on the response is ridiculous. Reading from files in blob storage... WTF?
Ctrl-F Redis - was disappointed.
Actually, even forget Redis. Pre-generate each of the 1 million possible HTTP responses and store in a string array. The 5 character hex is the index into the array. Write < 100 lines of Go to load the data structure and serve it. What am I missing?
This is like “Hello World” in those HTTP Framework Benchmarks that used to make the rounds every few months.
- th3byrdm4n 9y agoPrecisely my first thought. Static readonly data? Why isn't this just sitting in memory?
- mzzter 9y agoSounds reasonable, 500mil * 160 bits of SHA-1 would be 500 mb of space. Even with some metadata to manage it, the smallest instances should be able to handle that.
- lipnitsk 9y ago500,000,000*160bits/(8bits/byte)=10,000,000,000 bytes=9,536MB=9.313GB
- vortico 9y agoDon't filesystem caches basically do this for you?
- zaroth 9y agoYes but with a heck of a lot more overhead than; response.body = result[(int)hexCode];
- dullgiulio 9y agoYou can do that after mmap(2) and you never have to reach out for read(2). Might need to use unsafe language constructs though.
- tgsovlerkhgsel 9y agoNo, with a lot less overhead because you don't need to write custom web server code. Edit: and if he points the requests directly at blob storage as he's suggesting, we're very close to to flat files on a filesystem again.
- dpweb 9y agoFor an extreme diet, Id html app cache the pretty pictures. I know its deprecated but is still massive support in all browsers and is instantaneous fast. Removing all origin hits except api req for sure. On the lookups CF workers has a global state that is shared amongst nodes. Been playing with that. Wondering if you hold string array in that and can get the origin hits below 10% you can run this svc with many million reqs day practically for free. Vps tho, not amzn.
- quadrature 9y agoI think this solution is banking on storage + azure function cost being cheaper than the per instance cost to service the same load with an acceptable latency.
- djhworld 9y agoThe 250mb redis instance on Azure costs $0.055 an hour[1], so nearly $500 p/year Going down the small hosting a 100 line Go program route, the cheapest "B1" instance type with 1GiB of RAM costs $105.12 a year, and then if you want the service to be HA you need probably another instance in a different zone, maybe a load balancer as well. I suspect Azure Functions + Blob Storage costs a lot less. Although he didn't mention how much CloudFlare was costing him. [1] https://azure.microsoft.com/en-us/pricing/details/cache/ https://azure.microsoft.com/en-us/pricing/details/cache/ [2] https://azure.microsoft.com/en-us/pricing/details/virtual-machines/linux/ https://azure.microsoft.com/en-us/pricing/details/virtual-ma...
- jmiserez 9y agoHe mentioned that Cloudflare is free for him.
- dchuk 9y agoYou could host this whole thing on the cheapest Digitalocean droplet if it were written as the person you're replying to described.
- emodendroket 9y agoI'm guessing he didn't do that because he's a prominent .NET/Azure guy and I don't think that stuff is well-supported in that environment.
- manigandham 9y agoAnd then it's a single server that has none of the scaling, ease of maintenance, or high availability of just using functions and table storage. This is the perfect scenario for serverless, why would you want to run a VM instead? The current system works great, most of the hits will be cached, and optimizing the origin to be that milliseconds faster isn't worth it at all.
- dchuk 9y agoIt's actually NOT a perfect system for serverless, because it's a read-only (no writes), simple search "web app". The one thing that you don't get from a VM in your list is high availability I'll give you that, but otherwise this solution is an overengineered monstrosity for a simple problem if done in a more traditional way, as many many other people are calling out here. If the only reason your web app is fast is when its data is cached, you need to take a long hard look at how your web app is built. It's not that hard to build a performant query system like this even with that amount of data.
- nodesocket 9y agoCouldn't he run a simple KV Consul cluster in a few zones and regions in either AWS or Google Cloud and be done?
- manigandham 9y agoThat's ridiculously complex and more expensive than just writing two functions that call table storage and blog storage APIs. Given the popularity of serverless, I'm surprised by all these answers saying he should run actual VMs when this the perfect use-case for functions.