开发者

Memory leak using SQL FileStream

开发者 https://www.devze.com 2022-12-18 02:36 出处:网络
I have an application that uses a SQL FILESTREAM to store images.I insert a LOT of images (several millions images per days).

I have an application that uses a SQL FILESTREAM to store images. I insert a LOT of images (several millions images per days).

After a while, the machine stops responding and seem to be out of memory... Looking at the memory usage of the PC, we don't see any process taking a lot of memory (neither SQL or our application). We tried to kill our process and it didn't restore our machine... We then kill the SQL services and it didn't not restore to system. As a last resort, we even killed all processes (except the system ones) and the memory still remained high (we are looking in the task manager's performance tab). Only a reboot does the job at that point. We have tried on Win7, WinXP, Win2K3 server with alw开发者_运维知识库ays the same results.

Unfortunately, this isn't a one-shot deal, it happens every time.

Has anybody seen that kind of behaviour before? Are we doing something wrong using the SQL FILESTREAMS?


You say you insert a lot of images per day. What else do you do with the images? Do you update them, many reads?

Is your file system optimized for FILESTREAMs?

How do you read out the images?

If you do a lot of updates, remember that SQL Server will not modify the filestream object but create a new one and mark the old for deletion by the garbage collector. At some time the GC will trigger and start cleaning up the old mess. The problem with FILESTREAM is that it doesn't log a lot to the transaction log and thus the GC can be seriously delayed. If this is the problem it might be solved by forcing GC more often to maintain responsiveness. This can be done using the CHECKPOINT statement.

UPDATE: You shouldn't use FILESTREAM for small files (less than 1 MB). Millions of small files will cause problems for the filesystem and the Master File Table. Use varbinary in stead. See also Designing and implementing FILESTREAM storage

UPDATE 2: If you still insist on using the FILESTREAM for storage (you shouldn't for large amounts of small files), you must at least configure the file system accordingly.

Optimize the file system for large amount of small files (use these as tips and make sure you understand what they do before you apply)

  • Change the Master File Table reservation to maximum in registry (FSUTIL.exe behavior set mftzone 4)
  • Disable 8.3 file names (fsutil.exe behavior set disable8dot3 1)
  • Disable last access update(fsutil.exe behavior set disablelastaccess 1)
  • Reboot and create a new partition
  • Format the storage volumes using a block size that will fit most of the files (2k or 4k depending on you image files).
0

精彩评论

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

关注公众号