473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

alternative file.copy

it seems that when i do file.copy the svchost.exe is hanged, i mean if i make
40 threads of file.copy , 40 copys of files at same time the system is going
down and stop responding, this is when i'm working with cifs (shares). there
is another solution to copy files than file.copy in .net?
Nov 21 '05 #1
8 2898
"luis molina Micasoft" <lu****************@discussions.microsoft.com>
schrieb:
it seems that when i do file.copy the svchost.exe is hanged, i
mean if i make 40 threads of file.copy


Reduce the number of threads...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #2
Luis,

You make me curious, are you using threads to copy files, and then what is
the reason for that?

Cor

"luis molina Micasoft" <lu****************@discussions.microsoft.com>
....
it seems that when i do file.copy the svchost.exe is hanged, i mean if i
make
40 threads of file.copy , 40 copys of files at same time the system is
going
down and stop responding, this is when i'm working with cifs (shares).
there
is another solution to copy files than file.copy in .net?

Nov 21 '05 #3
Luis,
There are any number of alternatives to file.copy, some that work better
then others.

However! I'm not so sure that File.Copy is the problem as much as 40
File.Copy running at one time is.

To copy a file, you (or the Framework) needs open the source file, open the
destination file, read of chunk of data, write a chunk of data, repeat
reading & writing until there is no more data.

Depending on the size of the files & the size of the chunks, I would expect
40 copies to bring a system to its knees... I would expect adding network
shares to the mix would only compound the problem

Are you using the ThreadPool or creating the threads yourself.

I would consider using a thread safe Queue to hold the copy requests and
only start a handful of Workers. Each worker would get one copy request from
the Queue, copy the file, then get another request.

I would also consider using Asynchronous File I/O to copy the contents with
Stream.BeginRead & Stream.BeginWrite, allowing the overlapping of the reads
& writes, which may require reducing the number of Workers.

I'm not sure which ones, I suspect there are a handful of Performance
Counters that you could use to monitor the process and dynamically adjust
the number of Workers to match your system performance. System not being
stressed increase workers, system being stressed decrease workers... I know
MSDN magazine a few years ago had an article on how to use Performance
Counters to adjust number of workers...

Hope this helps
Jay

"luis molina Micasoft" <lu****************@discussions.microsoft.com> wrote
in message news:93**********************************@microsof t.com...
it seems that when i do file.copy the svchost.exe is hanged, i mean if i
make
40 threads of file.copy , 40 copys of files at same time the system is
going
down and stop responding, this is when i'm working with cifs (shares).
there
is another solution to copy files than file.copy in .net?

Nov 21 '05 #4
yes you got me, im not using a threadpool, and im trying to copy 20 or 40
files from uncs shares at same time with a independent thread for each one of
them, im gonna try with the threadpool and the asyncronous io, thanks for all.

"Jay B. Harlow [MVP - Outlook]" wrote:
Luis,
There are any number of alternatives to file.copy, some that work better
then others.

However! I'm not so sure that File.Copy is the problem as much as 40
File.Copy running at one time is.

To copy a file, you (or the Framework) needs open the source file, open the
destination file, read of chunk of data, write a chunk of data, repeat
reading & writing until there is no more data.

Depending on the size of the files & the size of the chunks, I would expect
40 copies to bring a system to its knees... I would expect adding network
shares to the mix would only compound the problem

Are you using the ThreadPool or creating the threads yourself.

I would consider using a thread safe Queue to hold the copy requests and
only start a handful of Workers. Each worker would get one copy request from
the Queue, copy the file, then get another request.

I would also consider using Asynchronous File I/O to copy the contents with
Stream.BeginRead & Stream.BeginWrite, allowing the overlapping of the reads
& writes, which may require reducing the number of Workers.

I'm not sure which ones, I suspect there are a handful of Performance
Counters that you could use to monitor the process and dynamically adjust
the number of Workers to match your system performance. System not being
stressed increase workers, system being stressed decrease workers... I know
MSDN magazine a few years ago had an article on how to use Performance
Counters to adjust number of workers...

Hope this helps
Jay

"luis molina Micasoft" <lu****************@discussions.microsoft.com> wrote
in message news:93**********************************@microsof t.com...
it seems that when i do file.copy the svchost.exe is hanged, i mean if i
make
40 threads of file.copy , 40 copys of files at same time the system is
going
down and stop responding, this is when i'm working with cifs (shares).
there
is another solution to copy files than file.copy in .net?


Nov 21 '05 #5
Jay,

I am quiet sure that using threads for diskcopying is useless. It gives you
even more threadmanaging processtime, and you even have even to check in a
strange way that you are not using twice the same filename in multiple
threads with the change that it will blow up your program because you cannot
control a part of this process.

Cor
Nov 21 '05 #6
Cor,
I am quiet sure that using threads for diskcopying is useless. I'm suspect, for you, you are correct! :-|
you even have even to check in a strange way that you are not using twice
the same filename in multiple Which is what the Thread Safe Queue is for. Here I am referring to a
System.Collections.Queue object. Then using either Queue.Synchronized to
create a thread safe Queue or encapsulate the Queue in your own class with
SyncLock statements to make it Thread Safe.

Seeing as a Queue is a First In First Out (FIFO) construct you would put all
the copy requests (an object with source name & destination name properties)
into the Queue. The workers would then read a request & process the copy.
the change that it will blow up your program because you cannot control a
part of this process. My change (using a Thread Safe Queue) is a standard pattern for
multi-threading, its the pattern that ThreadPool is based on (as suggested
by the method ThreadPool.QueueUserWorkItem)

Asynchronous File I/O is a standard pattern within the Framework.

http://msdn.microsoft.com/library/de...nousfileio.asp

I hope you realize my real suggestion to Luis was to limit the number of
requests, I was then offering alternatives that he may not have considered.

I do agree that one needs to be more careful writing multi-threaded
applications or not using Multi-threading, however as you reread the Luis's
original question, you will find he is already using Multi-threading!

Hope this helps
Jay
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl... Jay,

I am quiet sure that using threads for diskcopying is useless. It gives
you even more threadmanaging processtime, and you even have even to check
in a strange way that you are not using twice the same filename in
multiple threads with the change that it will blow up your program because
you cannot control a part of this process.

Cor

Nov 21 '05 #7
Luis,
Using the ThreadPool may not help per se.

My point is the number of requests going on. The ThreadPool will effectively
limit you to 25 requests. 25 requests may still be too many.

If I used the ThreadPool I would still try to limit the number of actual
copy requests going on...

Hope this helps
Jay

"luis molina Micasoft" <lu****************@discussions.microsoft.com> wrote
in message news:1A**********************************@microsof t.com...
yes you got me, im not using a threadpool, and im trying to copy 20 or 40
files from uncs shares at same time with a independent thread for each one
of
them, im gonna try with the threadpool and the asyncronous io, thanks for
all.

"Jay B. Harlow [MVP - Outlook]" wrote:
Luis,
There are any number of alternatives to file.copy, some that work better
then others.

However! I'm not so sure that File.Copy is the problem as much as 40
File.Copy running at one time is.

To copy a file, you (or the Framework) needs open the source file, open
the
destination file, read of chunk of data, write a chunk of data, repeat
reading & writing until there is no more data.

Depending on the size of the files & the size of the chunks, I would
expect
40 copies to bring a system to its knees... I would expect adding network
shares to the mix would only compound the problem

Are you using the ThreadPool or creating the threads yourself.

I would consider using a thread safe Queue to hold the copy requests and
only start a handful of Workers. Each worker would get one copy request
from
the Queue, copy the file, then get another request.

I would also consider using Asynchronous File I/O to copy the contents
with
Stream.BeginRead & Stream.BeginWrite, allowing the overlapping of the
reads
& writes, which may require reducing the number of Workers.

I'm not sure which ones, I suspect there are a handful of Performance
Counters that you could use to monitor the process and dynamically adjust
the number of Workers to match your system performance. System not being
stressed increase workers, system being stressed decrease workers... I
know
MSDN magazine a few years ago had an article on how to use Performance
Counters to adjust number of workers...

Hope this helps
Jay

"luis molina Micasoft" <lu****************@discussions.microsoft.com>
wrote
in message news:93**********************************@microsof t.com...
> it seems that when i do file.copy the svchost.exe is hanged, i mean if
> i
> make
> 40 threads of file.copy , 40 copys of files at same time the system is
> going
> down and stop responding, this is when i'm working with cifs (shares).
> there
> is another solution to copy files than file.copy in .net?


Nov 21 '05 #8
Nak
Hi Luis,

This is probably going to sound stupid, but arent multiple asynchronous
file operations slow because of hard drive technology? I'll give you an
example, copying a load of MP3's (50mb) from one drive to the other chugs
along quite happy, then when you throw just 1 more file copy to happen at
the same time the entire operation gets slowed down, and my understanding
for this is because the hard drive can't read / write that many sectors at
the same time.

Probably not helpful, but I thought I'd say it anyway! :-)

Nick.

"luis molina Micasoft" <lu****************@discussions.microsoft.com> wrote
in message news:93**********************************@microsof t.com...
it seems that when i do file.copy the svchost.exe is hanged, i mean if i
make
40 threads of file.copy , 40 copys of files at same time the system is
going
down and stop responding, this is when i'm working with cifs (shares).
there
is another solution to copy files than file.copy in .net?

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: b.b | last post by:
Is the days of VB6 we used to place all of our shared dll's in one central location on a separate server within our network domain. All apps that needed a shared dll would have the dll registered...
115
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i...
43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
14
by: ajfish | last post by:
Hi, I am trying to allocate a unique ID to every instance of tag 'foo' in a large XML document. currently I'm doing this: <xsl:variable name="UniqueId"> <xsl:number count="foo" level="any"/>...
3
by: none | last post by:
I have a very complex data structure which is basically a class object containing (sometimes many) other class objects, function references, ints, floats, etc. The man for the copy module states...
6
by: C10B | last post by:
hi, I have a table with several million rows. Each row is simply the date and time a certain page was viewed. eg page1 1-1-00 page2 2-1-00 page1 16-1-00 page1 17-1-00
13
by: andrewanderson | last post by:
hi all, i'm wondering is there any other alternative to do a timestamp which consists of date and time!! below is a program i've created but its too long and to large i would like to know other...
14
by: Adam Atlas | last post by:
I wrote this little program called Squisher that takes a ZIP file containing Python modules and generates a totally self-contained .pyc file that imports a specified module therein. (Conveniently,...
3
by: maheshkadam | last post by:
Hi friends I am new to perl so please guide me. I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.