21 ms·
> we used to do 20k mysql queries on a single page As a non-web developer, this is something that surprises me greatly. Why does loading a single page ever ne
by enriquto 6y ago
> we used to do 20k mysql queries on a single page
As a non-web developer, this is something that surprises me greatly. Why does loading a single page ever need to do a sql query? Can't you most often just generate all the possible static pages that you want to serve? Is your db content really changing every second?
- unnouinceput 6y agoe-commerce sites.
- enriquto 6y agoThat's exactly what I was thinking about. For example, last weekend I was looking at the products offered by an online bike shop. There were at most a few thousand pages showing product lists with prices. Some of these pages took more than a second (!) to load. What the hell is going on? What's the server doing all that time? That should be instantaneous. It can be solved by a small folder of static html pages, re-generated when stock changes a few times per week. I'm not a web developer so maybe what I say does not make sense and sounds stupid. But I'm just astonished by what process this happens to be a complicated problem.
- fogihujy 6y agoBased on the numerous e-commerce web sites I see on a daily basis, it's usually one or more of the following: * Inefficient, disabled, or non-existing caching. * Random SEO plug-ins/add-ons doing things like queries on non-indexed data or insanely convoluted JOINs. * Logging every single HTTP request into a single table that nobody ever remembers to truncate. * Multiple queries for each page in order to recommend similar products in the page footer or on some widget. * Checking whether the visitor is logged in, and if there's anything in the basket yet. * Checking whether there's an active discount for the current user/product combination. It's really quite ridiculous. The worst offenders are WordPress/WooCommerce sites. Dedicated e-commerce solutions usually fare better.
- unnouinceput 6y agoto quote you " ... re-generated when stock changes..." - that's exactly the correct wording, except it doesn't happen a few times per week, but a few times per millisecond if you're Amazon. Or a few times per minute if you're a national supplier, any country you want, and you have a sale on Black Friday. That, of course, assumes you want to have almost real-time inventory stock to show to your possible clients. Otherwise, if you don't care to show out of stock items, sure, it can be a few times per week.
- enriquto 6y agoBut they don't even solve that problem! In both shops that I use (rosebikes.fr and decathlon.fr) stocks are explicitly marked as approximate, with a very visible warning in red when the stock is 2 or 1 items, asking you to call the shop to verify stock. Website is slow as molasses still.
- unnouinceput 6y agoIn those particular cases then yeah, it might be a sloppy job, but you didn't made it sound like that initially, instead let us believe you meant it generally speaking
- Aeolun 6y agoThis was a page in an e-learning system showing student results. It was all calculated on page load and iirc there were a few too many ‘look all these things up for one student at a time’ kind of situations that compounded. You could cache that information, but you’d need to update it every time someone submits a new result (in this case to a test that can have tens of questions), times 30 students in class, times multiple tests. In hindsight I think we could maybe have precalculated the results after the last student finished, but that wouldn’t really be worth it for a page that took maybe a few seconds to load.