53 ms·
Potato Programming
- revskill 4y agoBatch processing is always easier to tune performance over real time one. Classic example: Batch upserting legacy data into new service. Instead of looping and try to search for existing items before insertion, we could search first, then insert in batch!
- necovek 4y agoIt's not always easier: the requirements are frequently different. Live processing requires progress updates for the user, and if it takes too long, is often relegated to batch jobs: other than that, it's equally easy or hard to optimize them for identical (absolute) time thresholds. Batch jobs are similarly prone to races, starvation and other issues: you can't simply do a huge "upsert" without locking the full table, because it might lock other parts of the system, including other batch jobs accessing the same data.
- revskill 4y agoThe point is "easier to tune performance", not only "easier". In real time processing, you have limited choice of course ?
- necovek 4y agoI don't see it: it's all exactly the same. If your performance goal is not achievable in time required for live processing (whatever you decide that to be), you just relegate to a background job and then it's the same as any other batch job. Sure, this is a slight complexity on top, but it's such a common and well known pattern that it doesn't really add any practical complexity after you do it once. It's a fallacy to think that it's any different.
- kgeist 4y agoYeah long time ago I noticed that if some concept/class can have more than 1 instance (i.e. it's not a singleton), eventually you will have to convert APIs to use arrays anyway, for optimization purposes, when the complexity of your app increases. So now, when designing public APIs, I prefer, for example, methods like ListObjects(spec) instead of FindObject(spec). FindObject is then a simple wrapper around ListObjects for the cases when we know it will return only one object, just for convenience (which can be implemented by the client, without adding it to the public API).
- moring 4y ago> The simplest change that we can make, as a consumer of these potato-shaped APIs, is to submit them in parallel. This is also a good way to check if their back-end code is free of race conditions, and after pointing out strange problems get a note from their developers that you should not send multiple concurrent requests to their REST API. Been there, done that, with a huge vendor for, well, accounting software.
- vrnvu 4y agoSo what the author is suggesting is basically improving cache locality using linear data structures. Use data structures that fits your CPU/GPU. Use algorithms that make good use of your CPU/GPU... Add branch prediction and good memory alignment to reduce page faults to the mix and you have the A, B, C of data-oriented design. Now, in order to apply this ideas to a higher level of design, i.e communication between microservices, we need to apply the same principles. Reduce expensive calls by sending all data required to a function at the same time, let the backend do the work, precompute/prefetch data that will make work easier later... Good advice in general. For me the highlight is that this approach can only be applied when we design and adapt our microservices to our computational needs instead of business. I still see a lot of gurus giving talks about splitting microservices in "business needs" and saying that anything else is a bad practice. Hold on, there is no silver bullet in engineering. Maybe the business logic is easy to understand, but this system design will make the system impossible (yes) to optimize in the future without a full re-write. And the same idea applies to low level design. Everything is a trade-off. My approach is to design the public API following domain/business principles so it's easy to understand and implement. A la DDD and others if you want to call them something. But I want my backend to be flexible and designed around the REAL engineering requirements. If my `/api/foo/bar` is an async batch process that needs to be cached and my `/api/foo/baz` is a complex sync process, then `bar` and `baz` are two completely monsters. I don't want to have a `foo` service to handle both use cases. Having a `foo` service just because it's a business concept will cost you hours and money.
- moring 4y ago> I still see a lot of gurus giving talks (...) saying that anything else is a bad practice. I have become very cautious when "gurus" speak about good/bad practice. My personal approach is to ask them which ultimate goal they intend to reach by that, and how their "good" practice is intended to reach that goal. Note that I'm not asking for certainty at all, or even a high chance. Just a clear intention. More often than not, they cannot outline a path from their "good" practice to their end goal. If they can even name a goal, that is. My favorite examples are splitting methods to reduce their size, and user story estimation (applies to both story points and man-days). No clear path to an end goal, not a single time so far.
- 082349872349872 4y agoVarious related ways to level up: - don't operate on register-sized parts, operate on whole objects - don't operate on single scalars, operate on whole arrays - don't operate just on data, operate even on operators what other members of this family exist? are worthwhile?
- greenbit 4y agoMy take away from a quick read: If there are N items here that all need to be processed by procedure P, the naive solution is to loop N times spoon feeding the items into P. The preferred solution is to have P take a reference to entire sets of items, specifically arrays of items. This is nice! This to me seems very sensible whether you have some fancy hardware doing P in parallel, or even just a plain old FOR loop - in the latter case it's the same length loop as the naive solution but you don't expose your procedure call mechanism to the loop. And it's a win on the calling side bc it'll help declutter the business logic there.
- dkersten 4y agoReminds me of Mike Acton’s talk on data-oriented programming, where he talked about writing functions to take arrays of things instead of single things, stating: Where there’s one, there’s many
- throwaway17_17 4y agoFor anyone interested: Mike Acton’s CPPCon Keynote 2014 is the usual reference for parent’s quote. [1] 1 - https://m.youtube.com/watch?v=rX0ItVEVjHc https://m.youtube.com/watch?v=rX0ItVEVjHc
- jrochkind1 4y ago> The performance difference involved in these two styles is not small. Consider this case study which shows a 5828% improvement4 when taking an algorithm from idiomatic pure Python to NumPy. I am not a python dev, but I've been told that's because Numpy is largely written in C, no? Rather than solely because of an array/vector-focused "style" -- 5000% faster?
- carlmr 4y agoThe array focused style enables efficient interaction with the C-written backend of numpy. You need to adapt your style (in Python) to get these performance gains. In a language like Rust you can write normal, readable code and get the same performance, plus you don't incur the penalty of copying data between the language boundaries.
- jrochkind1 4y agoThat makes sense, and still to me suggests the OP is inaccurate talking about where numpy's performance advantage came from: > NumPy. NumPy takes a similar approach: it cannot itself do anything to speed up Python’s fundamental interpreted execution speed3, but it can move the intensive numerical operations that it implements into operations on arrays, rather than operations on individual objects, whether numbers or not. The move to operations on arrays would do nothing if the logic wasn't also happening in the C-written backend -- in fact numpy _did_ do something about Python's fundamental interpreted execution speed, it moved the logic to the C backend. You point out that _also_ needed the move to array-based things to take full advantage of it, to minimize trips across the python/C boundary if I understand right. But the gain is not simply from changing from operations on individual objects to operations on arrays. This is not really a demonstration of the array "style" having amazing performance advantages (5000%!) in general, generalizable to any platform as the OP does. It is instead in the numpy case specific to the enviroment of Python with C bindings, and wanting to minimize trips across the python/C boundary.
- carlmr 4y ago>You point out that _also_ needed the move to array-based things to take full advantage of it, to minimize trips across the python/C boundary if I understand right. So yes and no. Moving to array-based operations removes the need for the for-loops in python that are slow. So you can do more on the C backend than in the slow Python frontend, by changing to an array-based style. If you did this for single numbers, the boundary operations would be too much to make this useful. By moving the array into the backend we have a lot of computations in C, so it's useful to incur the penalty at the boundary.
- daltont 4y agoFunny that I never heard of the idea of a device being a "potato" until my rather non-technical son (21 yro) used the term about whatever device took a low quality digital photo.
- 0x445442 4y agoI’m not seeing the great insight here. From my reading, it sounds like the author is saying something akin to; when performing some IO task like fetching line items from an order it is better to fetch all the line items at once related to the order than it is to fetch the order and then fetching each of its related line items in a loop. Incidentally, this is why I advocate for SQL in application code or the use of stored procedures. If I had a nickel for every time I’ve seen the latter example when ORMs were used.