开发者

Why does calling File.Delete() and File.Move() in ASP.NET cause my worker process to hang?

When I execute the following code to delete and move a file my worker process hangs:

File.Delete(FullSourceFilePath);
File.Move(FullTempFilePath, FullSourceFilePath);
// update db
Data.AdminUpdateFileSizeandBitrate(FileId, SizeInbytes, Bitrate);
Response.Redirec开发者_运维知识库t("?m=File replaced!");

The folder FullSourceFilePath has more than 15000 files in it.

Above code causes site to hang (only this site) if the file that needs to be moved is larger than around 5 MB. When this problem arises my worker process starts consuming memory and gradually my server is brought to its knees.

The only recovery solution is then to issue the IISRESET /RESTART command.

My environment is:

IIS6 running on Windows 2003 x86 SP2

Web site written using ASP.NET 4.0 and C#


At a guess, the problem here is probably the large number of files in the folder you're moving the file to.

Does the worker process hang just on the File.Move()?

Try doing:

File.Delete(FullSourceFilePath);
File.Copy(FullTempFilePath, FullSourceFilePath);

Other things to try are performing the same actions from the command line and see if that causes the same problem to arise.

If it does then you're filesystem may be heavily fragmented and the disk is thrashing.

Windows also doesn't handle large numbers of files very well, if the files can be categorised in any way (for example by ID range or date range) then break this down into subfolders.

You could also run DebugDiag and capture a minidump to see where the bottleneck is happening.

Tess Ferrandez' blog has some great articles on how to use this tool to determine causes of worker process high memory use, crashes and hangs.

.NET Debugging Demos - Information and setup instructions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜