I am developing a site which handles user input resulting in a graphical jpg image drawn using the GDI+ library. For better performance I only generate these images once, then save them to disk. For later reference I fetch the location from the database. Each user input results in three images (thumbnail, zoomed and one for the pdf-report), all in all about 60kb. We expect to have 100 – 1000 of these input a day.
I am now considering saving the images in the database (BLOB fields – I’m using MySql) and create a ashx handler page to display the images. The primary reason would be to make it easier to move the site from one server to another (not having to worry about read/write -rights on the servers file-system and not having to worry about broken links between db and file).
Would this change be advisable in my scenario? Would it have any significant positive or negative change in performance?
The impact on performance depends on your DB setup regarding HW (RAM, SSD etc.) and network (is it on the same machine as the app?).
Usually I recommend sticking to the file system because in my experience those files tend to get big sometimes (which would degrade the performance of the DB!) and the filesystem is better optimized to handle files than any DB.
OTOH if you are pretty sure about the sizes (max. 60 KB) AND your DB is sufficiently fast then go for it… make sure to put the BLOBs into a separate table with only other field (primary key), don’t keep any metadata etc. in the same table as the BLOBs!
One remark though:
I always recommend to make a thorough performance test (simulate users/load, use a profiler etc.) before deciding on such a change… create 2 versions of the ASHX handler – one that uses the DB only for the path and delivers the files from the filesystem and the second one does all via DB…