<oembed><type>rich</type><version>1.0</version><author_name>npub1sgs97fe0n9wehe6zw7drcxdz4cy9yt9pfqjv8gasz5jlk4zezc0quppx3c</author_name><author_url>https://nostr.ae/npub1sgs97fe0n9wehe6zw7drcxdz4cy9yt9pfqjv8gasz5jlk4zezc0quppx3c</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2017-04-07&#xA;📝 Original message:-----BEGIN PGP SIGNED MESSAGE-----&#xA;Hash: SHA256&#xA;&#xA;On 04/07/2017 11:39 AM, Bram Cohen via bitcoin-dev wrote:&#xA;&gt; Expanding on this question a bit, it&#39;s optimized for parallel&#xA;&gt; access, but hard drive access isn&#39;t parallel and memory accesses&#xA;&gt; are very fast, so shouldn&#39;t the target of optimization be about&#xA;&gt; cramming as much as possible in memory and minimizing disk&#xA;&gt; accesses?&#xA;&#xA;While this may seem to be the case it is not generally optimal. The&#xA;question is overly broad as one may or may not be optimizing for any&#xA;combination of:&#xA;&#xA;startup time (first usability)&#xA;warm-up time (priming)&#xA;shutdown time (flush)&#xA;fault tolerance (hard shutdown survivability)&#xA;top block validation (read speed)&#xA;full chain validation (read/write speed)&#xA;RAM consumption&#xA;Disk consumption&#xA;Query response&#xA;Servers (big RAM)&#xA;Desktops (small RAM)&#xA;Mining (fast validation)&#xA;Wallets (background performance)&#xA;SSD vs. HDD&#xA;&#xA;But even limiting the question to input validation, all of these&#xA;considerations (at least) are present.&#xA;&#xA;Ideally one wants the simplest implementation that is optimal under&#xA;all considerations. While this may be a unicorn, it is possible to&#xA;achieve a simple implementation (relative to alternatives) that allows&#xA;for the trade-offs necessary to be managed through configuration (by&#xA;the user and/or implementation).&#xA;&#xA;Shoving the entire data set into RAM has the obvious problem of&#xA;limited RAM. Eventually the OS will be paging more of the data back to&#xA;disk (as virtual RAM). In other words this does not scale, as a change&#xA;in hardware disproportionately impacts performance. Ideally one wants&#xA;the trade between &#34;disk&#34; and &#34;memory&#34; to be made by the underlying&#xA;platform, as that is its purpose. Creating one data structure for disk&#xA;and another for memory not only increases complexity, but denies the&#xA;platform visibility into this trade-off. As such the platform&#xA;eventually ends up working directly against the optimization.&#xA;&#xA;An on-disk structure that is not mapped into memory by the application&#xA;allows the operating system to maintain as much or as little state in&#xA;memory as it considers optimal, given the other tasks that the user&#xA;has given it. In the case of memory mapped files (which are optimized&#xA;by all operating systems as central to their virtual memory systems)&#xA;it is possible for everything from zero to the full store to be memory&#xA;resident.&#xA;&#xA;Optimization for lower memory platforms then becomes a process of&#xA;reducing the need for paging. This is the purpose of a cache. The seam&#xA;between disk and memory can be filled quite nicely by a small amount&#xA;of cache. On high RAM systems any cache is actually a de-optimization&#xA;but on low RAM systems it can prevent excessive paging. This is&#xA;directly analogous to a CPU cache. There are clear optimal points in&#xA;terms of cache size, and the implementation and management of such a&#xA;cache can and should be internal to a store. Of course a cache cannot&#xA;provide perfect scale all the way to zero RAM, but it scales quite&#xA;well for actual systems.&#xA;&#xA;While a particular drive may not support parallel operations one&#xA;should not assume that a disk-based store does not benefit from&#xA;parallelism. Simply refer to the model described above and you will&#xA;see that with enough memory the entire blockchain can be&#xA;memory-resident, and for high performance operations a fraction of&#xA;that is sufficient for a high degree of parallelism.&#xA;&#xA;In practice a cache of about 10k transactions worth of outputs is&#xA;optimal for 8GB RAM. This requires just a few blocks for warm-up,&#xA;which can be primed in inconsequential time at startup. Fault&#xA;tolerance can be managed by flushing after all writes, which also&#xA;reduces shutdown time to zero. For higher performance systems,&#xA;flushing can be disabled entirely, increasing shutdown time but also&#xA;dramatically increasing write performance. Given that the blockchain&#xA;is a cache, this is a very reasonable trade-off in some scenarios. The&#xA;model works just as well with HDD as SSD, although certainly SSD&#xA;performs better overall.&#xA;&#xA;e&#xA;-----BEGIN PGP SIGNATURE-----&#xA;Version: GnuPG v2.0.22 (GNU/Linux)&#xA;&#xA;iQEcBAEBCAAGBQJY5+7GAAoJEDzYwH8LXOFOsAsH/3QK55aWH6sAi6OsTwV1FLZV&#xA;Y/2SSjwn1vUh55MDkPpCxDwV99JqVwpk0vGM8mGg5s4ZS8sxOPqwGiBz/SZWbF9v&#xA;oStJS0DjUPnbYtI/mrC30GuAYVcKnc5DFDHvjX6f0xrLIzViFR7eiW0npUH6Xipt&#xA;RI9Mockaf1CqqGExtbIqWal0YDEQGH0ekXRp7uEjh8nPUoKqTVvxDCgqVooQfvfx&#xA;EeKX9ruSv/r91EM1JQuH8HBBF7+R24tmMtwbpGx0zrDg5ytpIyrRzVH/ze1Mj2a3&#xA;ZxThvofGzhKcDiTPWiJI11DBYUvhSH4Kx0uWLzFUA0gxPfWkZQKJWNDl2CEwljk=&#xA;=C7rD&#xA;-----END PGP SIGNATURE-----</html></oembed>