Writing to external HDD is slower than should be

Dear All,

Please someone advise on this. I have a 2,5" external HDD attached to the router which supports USB 3.0. I got good speed when copy some file to the HDD directly connected to the laptop. When I use SMB share the writing goes up to only 20MB/s. I did some checks below:

/dev/sda1: LABEL="Maxtor" UUID="bbf25799-766c-e345-b611-037ea0ba2b1b" TYPE="ext4" PARTUUID="e177740a-01"

root@XiaomiMiRouter3G:~# lsusb -D /dev/bus/usb/002/003
Device: ID 0bc2:61b6 Seagate RSS LLC Maxtor HX-M101TCB/GM [M3 Portable 1TB]
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 3.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 9
idVendor 0x0bc2 Seagate RSS LLC
idProduct 0x61b6 Maxtor HX-M101TCB/GM [M3 Portable 1TB]

root@XiaomiMiRouter3G:~# hdparm -tT /dev/sda1

/dev/sda1:
Timing cached reads: 284 MB in 2.01 seconds = 141.54 MB/sec
Timing buffered disk reads: 288 MB in 3.00 seconds = 95.92 MB/sec

root@XiaomiMiRouter3G:~# lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-mtk/1p, 5000M
|__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-mtk/2p, 480M

This is when the HDD is connected to the laptop itself:
copy4

powered by: Lede-18.01 r7190

That's expected performance using Samba on a dual core MIPS CPU (no multithreading).

1 Like

You shouldn't forget, the Xiaomi is a router and not a fileserver. The main purpose is dealing with ip pakets and not managing files.

1 Like

You might try to format the drive with "crippled" ext4 (no journal, no timestamps etc.) or ext2.
To reduce the strain on the routers CPU.

1 Like

I know this is a router and I would not expect any better, but I have read from several people (that is the experience) using samba with this router, that 2 or even 3 times higher transfer speed can be reached, but unfortunately, so far, I could not figure out what do I do differently.

@ reinerotto Okay, I will try it. Thanks for the suggestion.

1 Like

Can I format the disk within Openwrt? I did install Ubuntu under Vmware Workstation 14 pro, the usb controller supports 3.0, but my device is not visible, maybe it is not support ext4?

Yes, you can format ext4 using openwrt. However, needs additional package(s), i.e. e2fsprogs.
https://wiki.openwrt.org/doc/howto/storage

allright, thanks. Can you take a look into this, please?
These are the needed commands? Is the order of them counts?

mkfs.ext4
mkfs.ext4 -m 0 /dev/sda1

/etc/fstab
/dev/sda1 / ext4 defaults, noatime 0 1

unmount disk
tune2fs -O "^has_journal" /dev/sda1 (shouldn't I tell the router it is for ext4? like tune2fs.ext4?)
mount disk

Anything else I left out?

BR,

Sorry, I do not remember details, so I can only agree to your posting, that in general you are correct. You have the important features: noatime, and journal disabled. Very good.
Be advised, that there is some type of "automount" in /etc/config, which you might use.
Something like
uci set fstab.@mount[0].enabled='1'
uci set fstab.@mount[0].options='noatime'
Sorry, no more details available.

Just a note: You really need to distinguish between read and write speeds. Performance differs wildly between reading and writing.

These are read speeds. Don't expect to get anything close to that for write speeds. I will gladly stand corrected, but I'd say realistically you can expect ~30 MB/s, give or take a few. You can do a quick test for your write speed using the following command:

# time dd if=/dev/zero of=tempfile bs=1M count=1024

(adjust the output file to be written to a mounted filesystem of course). This will write a 1024 MB test file to disk. OpenWrt's dd does not state speed itself, so we time the action and you divide 1024 by the resulting seconds to get MB/s.

You will probably find that you can't even directly write to your disk at the "2 or 3 times", i.e. 40 to 60 MB/s speed you expect. I know my 800 MHz MBL SoC can't break 30 MB/s at write, and the drive there is connected straight to on-board SATA. Combined with the fact that samba itself takes up significant CPU performance, you will probably have to adjust your expectations.

You can try to optimize your file system, but don't expect anything close to a 2 or even 3 times performance increase. Personally, I found that beyond "sensible" settings ("noatime" is really a no-brainer), these optimizations don't really make much of a performance difference in the end. The main limitation is your CPU, and maxing out at ~20 MB/s is already quite good for a budget router.

Yes probably you are right. Other file share system like NFS can maybe increase the performance a bit? I Will not use all feature of samba, I think. Isn't NFS lighter CPU wise?

root@XiaomiMiRouter3G:~# time dd if=/dev/zero of=tempfile bs=1M count=102
4
1024+0 records in
1024+0 records out
real 0m 44.69s
user 0m 0.00s
sys 0m 13.37s
root@XiaomiMiRouter3G:~# time dd if=/dev/zero of=tempfile bs=1M count=1024
1024+0 records in
1024+0 records out
real 0m 53.17s
user 0m 0.02s
sys 0m 20.59s
root@XiaomiMiRouter3G:~# time dd if=/dev/zero of=tempfile bs=1M count=1024
1024+0 records in
1024+0 records out
real 0m 51.28s
user 0m 0.02s
sys 0m 20.32s

cpu
I checked during the test and it seems the CPU usage didn't went up to nearly 100%.

It is not getting better:

/dev/sda1 /share/Maxtor ext4 rw,noatime,nodiratime,block_validity,delalloc,nojournal_checksum,barrier,user_xattr 0 0

root@XiaomiMiRouter3G:~# time dd if=/dev/zero of=tempfile bs=1M count=1024
1024+0 records in
1024+0 records out
real 0m 59.99s
user 0m 0.00s
sys 0m 21.00s

Did you (and verified)
tune2fs -O "^has_journal" /dev/sda1
before benchmark ?

I did before and after it. Nothing really changed. Should I try again but now partition to GPT ?

MBR and GPT are partition information, they don't change anything about the file system or its performance.

That too is normal. Most of the CPU load will be in I/O, not in the dd process.

I'm inclined to say that (unless there's some advanced sorcery for USB I'm not aware of) you've hit the limits of your setup.

This is an interesting benchmark... I'm a LEDE/OpenWRT novice, but I have recently configured my TP-Link Archer c2600 to support USB, but in this instance I have used a NTFS formatted 16GB USB 3.0 thumb drive.

I only use NTFS drives as I require to use the same drive on Windows based systems.

I used the mentioned command...

_root@LEDE:~# **time dd if=/dev/zero of=/mnt/sda1/tempfile bs=1M count=1024**_
_1024+0 records in_
_1024+0 records out_
_real    2m 21.88s_
_user    0m 0.03s_
sys     0m 14.00s

So do I divide the 1024 by 21.88s or 14.00s to ascertain the write speed?

The filesystem is NOT the problem. As you can see in your first post, hdparm showed ~95MB/s speed. thats very good.

The problem is samba in combination with the router and its cpu. samba needs a lot of cpu power!! Use nfs or get a more powerfull router based on x86

Where have you read that?