One of my needs is to manage a shared resource (more like a read and write log)
among different processes (and also several threads) in the application. Data should also be
saved when the system restarts, so it must be a physical file / database.
A shared resource is some data that contains information about a key, a value. (so a possible operation that can be performed with this shared resource is to add new information about the key value,
update / delete existing key value information).
Therefore, I am thinking about using an xml file to store information physically, and a sample of the content will be
<Root> <Key1>Value</Key1> <Key2>Value</Key2> <Key3>Value</Key3> </Root>
The interface for reading and operations will look like this:
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, therefore, the solution is xml and if the data grows I will transfer it to the database. In addition, writing data will be larger compared to a read operation.
A few design questions / considerations related to the above scenario,
Is it possible to process 500 MB of data in an XML file?
Suppose the file is as xml. Now, how to take care of performance evaluation?
- I am thinking of caching ( MemoryCache class in .Net) data like a dictionary, this will allow
to achieve performance during the read operation, is it ok to cache 500 MB of data in memory or we
is there another option?
Now, if I use the above caching mechanism, what should happen during the write operation:
Do I have to write the contents of the dictionary in xml again during each write operation, converting
whole dictionary for xml? or - is there a way to update only part of the xml file whose data becomes modified / added? or any
another way to handle this scenario? - Should I improve performance again by putting a write operation in the queue and in the background
the thread reads the queue and activates the actual write operation, so the one who actually writes the data
Will not suffer due to writing to a file? - To handle multi-threaded script, planning to use Mutex with a global name, are there any others
best way to do this?
I'm sure I work with a few assumptions and tried to build from there, and if I'm wrong with
some assumptions, this will change most of the design concept. Consequently, a completely new solution is also
welcome (maintaining performance as the main criteria). Thanks in advance.