Solved NFS compressratio problem

Hi guys, I'm a new user to freeBSD.
I created a zpool and set compress to lz4 , then started the NFS server.
After writing some files from the client (ubuntu), I noticed that the compressratio remains to be 1.00x.
Code:
root@freeBSD_Mixcro:/nfs # zfs get compressratio
NAME                PROPERTY       VALUE  SOURCE
nfs                 compressratio  1.00x  -
------
Here are all the steps I did:
NFS_SERVER:freeBSD 192.168.2.91
Create zpool:
root@freeBSD_Mixcro:~ # zpool create nfs ada2
Enable compress:
root@freeBSD_Mixcro:~ # zfs set compress=lz4 nfs
Check compress:
Code:
root@freeBSD_Mixcro:~ # zfs get compress
NAME                PROPERTY     VALUE     SOURCE
nfs                 compression  lz4       local
/etc/rc.conf added:
Code:
# nfs_server
rpcbind_enable="YES"
nfs_server_enable="YES"
mountd_flags="-r"
/etc/exports added:
Code:
/nfs -alldirs -maproot=root 192.168.2.129
NFS_CLIENT:ubuntu 16.04 192.168.2.129
Mount NFS:
mount -t nfs 192.168.2.91:/nfs /nfs
Check mount:
Code:
root@STEI:~# df -h
Filesystem         Size  Used Avail Use% Mounted on
192.168.2.91:/nfs  2.7T  1.3T  1.4T  49% /nfs
...
Problems
All the data in /nfs was write from the client. But the compressratio is 1.00x.
Code:
root@freeBSD_Mixcro:/nfs # zfs get compressratio
NAME                PROPERTY       VALUE  SOURCE
nfs                 compressratio  1.00x  -
To figure out what really happens, I used dd to create a file with zero:
Code:
dd if=/dev/zero of=/nfs/test.zero bs=8k count=30000
30000+0 records in
30000+0 records out
245760000 bytes (246 MB, 234 MiB) copied, 2.33184 s, 105 MB/s
And this file actual size is 512B (checked in both side), the compress seems working:
Code:
root@STEI:/nfs# du -h test.zero
512    test.zero
Code:
root@freeBSD_Mixcro:/nfs # du -h test.zero
512B    test.zero
However, the compressratio remains 1.00x:
Code:
root@freeBSD_Mixcro:/nfs # zfs get compressratio
NAME                PROPERTY       VALUE  SOURCE
nfs                 compressratio  1.00x  -
So I retry to write a bigger zero file and monitored the net & disk activities:
6247

6249

6250


I do not understand why my disk works so hard and whether compress works or not in NFS server?
 
Compression is only done for new writes. It doesn't affect existing files.

Also note that a compression of a single file isn't going to change the average overal compression much. The difference is likely several digits after the decimal point. Meaning when rounded off you still get 1.00. The reality might be something like 1.00000001.

Also keep in mind that files like JPGs are already compressed (compression is part of the file format). So additional compression isn't going to do much. Plain text files on the other hand typically compress really well. So how much compression you get is going to depend on the type of data being stored. If the data is already compressed (.tgz for example) compression on the filesystem isn't going to add much.

None of this has anything to do with NFS.
 
Also note that LZ4 has an early-abort configuration, meaning, if the first X MB of the file don't compress to a size below a specific threshold, than the compression is aborted and the file is written to disk normally. This is done to prevent it from wasting time compressing already compressed files (like JPEGs and MPEGs and such) or from wasting time compressing something that isn't compressible.

If you want to force a compression scheme, regardless of the file type, then you need to pick one of the other compression schemes (like gzip-9). You'll get a compressratio out of it, but you'll waste a lot of CPU doing so. :)
 
Thanks for your help.
Just as you said, most of my files are compressed video.?
So I created another zpool and filled it with zero again. In this time I observed the changes in compressratio.
 
Back
Top