One of my need is to manage the shared resource (more like a log , with both read and write operation)
among different processes (thus multiple threads also) with in an application. The data should also be
persisted with system restarts hence it should be a physical file/database.
The shared resource is some data which has a key , value information. (so possible operation which can be done with this shared resource is add a new key value info ,
update/delete the existing key value info).
Hence I am thinking about using a xml file to store the info physically , and the sample content will
look like ,
<Root>
<Key1>Value</Key1>
<Key2>Value</Key2>
<Key3>Value</Key3>
</Root>
The interface to do the read and operation will look like ,
public interface IDataHandler
{
IDictionary<string,string> GetData();
void SetData(string key,string value);
}
I could assume that the data will not cross more than 500 MB hence the xml decision and if the data grows I will move it to DB. Also , writing of data will be more when compared to read operation.
Few queries/design considerations related to the above scenario are,
Is this fine to handle 500 MB of data in a xml file ?
Assuming the file as xml , Now how to take care of the performance consideration ?
- I am thinking about caching (MemoryCache class in .Net) the data as Dictionary , this will enable
to achieve the performance during read operation , Is it ok to cache 500 MB of data in-memory or do we
have some other option?
Now , if I use the above cache mechanism , what should happen during the write operation :
Should I write the dictionary content into xml again during every write operation by converting the
whole dictionary to xml ? or - is there any way to update only portion of the xml file whose data is getting modified/added ? or any
other way to handle this scenario ? - Should I again improve the performance by putting the write operation into Queue and in a background
thread read the queue and enable the actual write operation so that the one who actually writes the data
will not get affected because of write to file ? - To handle multi-thread scenario , planning to use Mutex with global name , is there any other
better way to do it ?
I am sure , I am operation with few assumption and tried to built from there and if I am wrong with
certain assumptions then it would change most of the design concept. Hence entirely new solution is also
welcome(keeping performance as main criteria). Thanks in advance.