Reducing the Cost of Writing to Disk
Join the DZone community and get the full member experience.Join For Free
so, we found out that the major cost of random writes in our tests was actually writing to disk. writing 500k sequential items resulted in about 300 mb being written. writing 500k random items resulted in over 2.3 gb being written.
note: i would like to point out alex’s comment , which helped setup this post.
so the obvious thing to do would be to use compression. i decided to try and see what that would give us, and the easiest thing to do is to just enable file compression at the ntfs level. but we can probably do better. the major cost we have is writes to the journal file. and we only ever read from the journal file when we recover the database. we are also usually writing multiple pages at a time for most transactions, and for the scenario we care about, writing 100 random values in a single transaction, we are usually write about a 100 pages or so anyway. that means that we have got a pretty big buffer that we can try to compress all at once.
sadly, we don’t really see a meaningful improvement under that scenario. using ntfs compression slow us down considerably , while both lz4 and snappy resulted in greatly reduce file writes, but roughly the same performance.
note that i have done just the minimal amount of work required to test this out. i changed how we are writing to the journal, and disabled reading from it. that was pretty disappointing, to tell you the truth, i fully expected that we’ll see some interesting improvements there. the lz4 compression factor is about x10 for our data set. that means that 100 – 121 pages usually are compressed to 10 – 13 pages.
the good thing about this is that running this through the profiler shows that we are running on a high i/o machine, where the amount and speed of i/o doesn’t impact our performance much.
to test it out, i run the same test on an amazon m3.2xlarge machine, and got the following results (writing to the c: drive):
so for now i think that i’ll do the following. we’ll focus on the other costs beyond i/o, and profile heavily on systems with higher i/o costs.
compression should work, in fact, my first thought was that we pay for less i/o with more cpu, but that is a guess without looking at the numbers.
here is the cost of committing using compression (lz4):
and here it is without compression:
so the good news is that we can visible see that we reduced the i/o cost from 8 seconds to 3.8 seconds. and even with compression cost of 2.6 seconds, we are still ahead.
however, the cost of the collections used is actually a lot worse from our perspective. so we are back to reducing computation costs first, then looking at compression again at a later point in time.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Top 10 Pillars of Zero Trust Networks
Merge GraphQL Schemas Using Apollo Server and Koa
Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
Mastering Time Series Analysis: Techniques, Models, and Strategies