views:

223

answers:

1

I wrote my own PageStatePersister class based on SessionPageStatePersister which writes the most recent 10 Viewstates for a session to a shared disk. I figure this will scale better than  keeping Viewstate in session since all web servers have access to it, they won't have to deal with expiration, and use less memory.

When a user closes the browser it notifies the server and the server deletes those files which have not been accessed for two hours. So far so good but I'm wondering if it will be faster and more efficient to store Viewstate in an SQL server database instead.

  1. Each ViewState file is 30k on average. 
  2. Currently it just reads a hidden field to get a Viewstate key and access the file directly and deserialize. There's no need to sort or search.
  3. There will be about 2000 concurrent users each hour and saving last recent 20 Viewstate sessions will be about 20k temp view files per hour.
  4. It must periodically iterate through files and delete the oldest file.

So which is better in this case: a flatfile system or a database?

+2  A: 

It would scale much better to store the ViewState in SQL Server. If you eventually want to increase from 10 most recent to 50 most recent, for example, it would be a relatively trivial increase in DB load. Disk I/O should generally be avoided whenever possible, moreso than DB I/O. Cleanup operations would also work much better, as seeking across a wasteland of abandoned files on disk is probably much heavier than WHERE DateInserted > 20 minutes ago.

Rex M