multithreading - efficiently saving image files to disk c# -


we're developing multi-sensor aquisition tool, , we're experiencing problems saving images (from webcam) hard drive.

we using 3 threads purpose:

  • one thread continuously gathers captured image webcam.
  • a timer thread collects last image , sends file saving method.
  • the timer thread calls third thread save, in order not interfere main timer thread functionality.

this works fine low frequencies. when raise fps around 30, start losing images. notice have multiple sensors , not webcam. that's why we're using architecture , not directly saving files webcam thread (we need keep synced)

this current implementation of save method:

private void saveimageframe(bitmap b, ulong frameid)     {         string filesavepath = _path+ "//";         if (b != null)         {             task.factory.startnew(() =>             {                 lock (_lock)                 {                     bitmap tosave = new bitmap(b);                     string filename = filesavepath + frameid.tostring() + ".bmp";                     tosave.save(filename);                 }             });         }     } 

we tried without task thread (for saving) , without lock. these 2 result in race conditions, since saving takes more time timer time interval.

i'm sure there better ways both in terms of architecture , .net functions. in enhancing performance of appreciated!

it's quite possible disk isn't fast enough. fast disk subsystem can sustain write speed of perhaps 100 megabytes per second, , that's if have file open. you're trying create 30 or more files per second, in pretty big load on system. add time required write data, , you're pushing file system's capabilities.

that problem worse number of files in folder increases. if have, say, 1,000 files in folder, things work pretty quickly. put 10,000 files in single folder , you'll find takes long time create new file in folder.

if bumping against hardware performance limitations, have several courses of action:

  1. get faster hardware. second, fast, dedicated drive, example.
  2. reduce number of files create. perhaps can save multiple images in compressed format , write them single file disk (a zip file, example). or reduce frame rate.
  3. reduce amount of data write (through compression or reducing image size).

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -