Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit speed of File.Copy

Tags:

c#

.net

file

copy

We're using a simple File.Copy in C# for moving our database backups to extra locations.

However on some servers, this causes the SQL server to pretty much stop working. These servers have very limited memory, so they're paging data out to the harddrive every so often.

Whilst we should buy more memory, this is not going to happen for a long time :-/

So I'm wondering if I can somehow limit the speed of the File.Copy operation ? (Thereby giving the SQL server some room to access the harddrive)

I could use an "old school" approach with two streams, reading and writing through a buffer, and just sleep 5 ms or so between reads. But I'd really prefer a neater solution, if such a one is available.

like image 284
Steffen Avatar asked Jul 02 '10 11:07

Steffen


People also ask

What determines the speed of copying files?

If you have more ram more data can be transferred making it faster. Second there are different speeds for usb's too both for the pendrives and for the part in the computer that you plug your pendrive into. They too affect the speed of the transfer.

Why is my file copy speed so slow?

Slow file copying can be caused by storage issues, client issues, and server issues. On the file server that hosts the shared folder, copy the file to its local hard disk. If the file-copying speed is unusually low (much slower than average speed), try to update the driver for your storage.

Is it faster to copy multiple files at once?

The physical head movement (latency) is what will slow a transfer from a spinning platter disk. If you were copying from a single HDD, then you would start a single big transfer rather than lots of small ones. The head going back and forth between two or more files that are being copied is what slows the transfer.


1 Answers

CopyFileEx might do what you need - it has a callback function that you could use as an artificial slowing method (haven't tried that for this scenario though so I am unsure about real effects - worth a try IMHO).

like image 153
Jaroslav Jandek Avatar answered Oct 03 '22 10:10

Jaroslav Jandek