zfs raidz and mirror

https://www.ixsystems.com/community/threads/some-differences-between-raidz-and-mirrors-and-why-we-use-mirrors-for-block-storage.44068/

ZFS is a complicated, powerful system. Unfortunately, it isn't actually magic, and there's a lot of opportunity for disappointment if you don't understand what's going on.

RAIDZ (including Z2, Z3) is good for storing large sequential files. ZFS will allocate long, contiguous stretches of disk for large blocks of data, compressing them, and storing the parity in an efficient manner. RAIDZ makes very good use of the raw disk space available when you are using it in this fashion. However, RAIDZ is not good at storing small blocks of data. To illustrate what I mean, consider the case where you wish to store an 8K block of data on RAIDZ3. In order to store that, you store the 8K data block, then three additional parity blocks... not efficient. Further, from an IOPS perspective, a RAIDZ vdev tends to exhibit the IOPS behaviour of a single component disk (and the slowest one, at that).

So we see a lot of people coming into the forums trying to store VM data on their 12 disk wide RAIDZ2 and wonder why their 12 disk 30 TB array sucks for performance. It's exhibiting the speed of a single disk.

The solution to this is mirrors. Mirrors aren't as good at making good use of the raw disk space (because you only end up with 1/2 or 1/3 the space), but in return for the greater resource commitment, you get much better performance. First, mirrors do not consume a variable amount of space for parity. Second, you're likely to have more vdevs. That 12 drive system we were just talking about will have 4 three-way mirrors or 6 two-way mirrors, which is 4x or 6x the number of vdevs. This translates directly to greatly enhanced performance!

Another substantial performance enhancement with ZFS is to maintain low pool occupancy rates.




For RAIDZ style file storage, it's commonly thought that performance will suffer once you pass the 80% mark, but this isn't quite right. It's a combination of fragmentation and occupancy that causes performance to suffer.

For mirrors, this is also true, but because the data being stored is often VM disk files or database files, it becomes more complicated. Because it is a copy-on-write filesystem, rewriting a block in a VM disk file causes a new block somewhere else to be allocated, and creates a hole where the old block was, when that block is freed (after any snapshots are released, etc). When writing new data, ZFS likes to allocate contiguous regions of disk to write its transaction groups. An interesting side effect of this is that if you are rewriting VM disk blocks 1, 5000, 22222, and 876543, these may actually be written as sequentially allocated blocks when ZFS dumps that transaction group to disk. A normal disk array would have to do four seeks to do those writes, but ZFS *may* be able to write them sequentially. Taken to its logical conclusion, when ZFS has massive amounts of free space available to work with, it can potentially be five or ten times faster at performing writes than a conventional disk array. The downside? ZFS will suffer if it lacks that free space.

If you want really fast VM writes, keep your occupancy rates low. As low as 10-25% if possible. Going past 50% may eventually lead to very poor performance as fragmentation grows with age and rewrites.

None of this helps with reads, of course, which over time become highly fragmented. ZFS typically mitigates this with gobs of ARC and L2ARC, which allow it to serve up the most frequently accessed data from the cache.

zpool txg_sync

Tuning needed for zfs parameters or server vm

How to tune zfs or system itself so that txg_sync is not in uninterrupted sleep state ?  ubuntu server 16.04 (kernel 4.15)installed on ZFS backed(no ext4 or xfs), below is zpool status. the server has [256 GB of memory and 46 core cpu] and HDD is 10K SAS drives(no SSD disk). the pool "root_pool" is created with below options enabledashift=12, atime=off , canmount=off ,compression=lz4,logbias=throughput,sync=disabled and No deduplication is enabled (zfs get all output in end)
zpool status 
  pool: root_pool
 state: ONLINE
  scan: none requested
config:
NAME        STATE     READ WRITE CKSUM
root_pool     ONLINE       0     0     0
  sda2      ONLINE       0     0     0
errors: No known data errors
  pool: PoolB
 state: ONLINE
  scan: none requested
config:
NAME        STATE     READ WRITE CKSUM
PoolB  ONLINE       0     0     0
  sdb       ONLINE       0     0     0
errors: No known data errors
# lsblk
NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16  0 1T 0 disk 
├─sdb9  8:25  0 8M 0 part 
└─sdb1  8:17  0 1024G 0 part 
zd0 230:0 0 4G 0 disk 
sda 8:0 0 1T 0 disk 
├─sda2  8:2 0 1024G 0 part 
├─sda9  8:9 0 8M 0 part 
└─sda1  8:1 0 1007K 0 part 
below is a snippet of the output of iostat -x  where the %iowait value is constantly 5% to 13%
when i search for the process in interruptible sleep
S   PID CMD
D  5858 [txg_sync]
D  4356 [txg_sync]
above is process name I see 99% of the time and the pid 4356 doesn't change
Below is output of zfs getall root_pool/logs which is more io intensive
NAME     PROPERTY              VALUE                  SOURCE
root_pool  type                  filesystem             -
root_pool  creation              Wed Nov 28  8:06 2018  -
root_pool  used                  621G                   -
root_pool  available             363G                   -
root_pool  referenced            96K                    -
root_pool  compressratio         3.62x                  -
root_pool  mounted               no                     -
root_pool  quota                 none                   defau        
sda is maxed out at %util 100. And it's a single-disk pool, so that doesn't likely mean sda is failing, it just means you're asking it to do more than a single disk can do.
Tuning isn't going to fix this, you just plain need more IOPS. Your options are 1. add more vdevs to the pool or 2. replace sda with an SSD.
In general, the IOPS profile of a pool is additive of all vdevs. So you have a single vdev (whether it's one disk, or a six-disk stripe) you get one disk's worth of IOPS. You add a second vdev (again, whether single disk, or n-wide stripe) and you get another disk's worth of IOPS. This is a general trend, not a hard-and-fast exact measurement, but it's good enough for calculations.
You'll be able to roughly double the performance you're seeing now if you add another vdev to the root pool. Of course, you'll also be roughly doubling the likelihood of a failure than can bring the pool low, since you're rocking single-disk vdevs, and therefore have no parity or redundancy. Whether this is acceptable or not is up to you, but be certain you've thought through the consequences of a catastrophic pool failure.
A single decent SSD will give you three orders of magnitude more IOPS than that 10K SAS disk you're using right now. The kicker is going to be the cost per TB of storage. If you're storing a lot of data, you might need to just add more spindles instead. If you do add more vdevs, you're going to need to balance the data you've already got; this ideally would mean backing data up externally, destroying the pool, then copying the data back on board after adding the new vdevs. You canjust add the vdevs, backup the data, then delete the data (and all snapshots containing it) then copy it back on the expanded pool... but it's cleaner to just destroy it.
If you switch from single disk vdevs to mirrors, you get more options. Each vdev still only gives you a single disk worth of write IOPS, but it gives you two disks' worth of read IOPS - probably not critical for a log server - and it gives you the ability to rebalance data on-the-fly with a small risk window:
  • scrub the pool (do not skip this initial step!)
  • detach one disk from each mirror
  • create a new pool with the detached disks, and any new disks you're adding
  • replicate from old pool to new
  • quiesce any write sources
  • replicate from old to new again (will go extremely rapidly; typically <1 min)
  • destroy old pool
  • export new pool, reimport new pool with old pool's name
  • attach remaining disks from destroyed pool to disks in new pool to upgrade from single-disk vdevs to mirror vdevs again
  • de-quiesce data sources
https://www.reddit.com/r/zfs/comments/7l64mt/what_zol_performance_optimization_settings_do_you/