How to improve read performance of XML records

I have two .NET applications that work independently (can run in any order or be just one run) that uses XML as a data store. In this way, both applications can read and write to the XML file. To update the data, I load an XML file from disk every time before read and write operations. And I use an XPath query to query a specific node. Now, there is a performance problem in this method, since XML read and write requests from one application each time (it uses polling and cannot be changed) I'm not sure what exactly causes a performance hit, but I believe that it is continuously written to read .

I tried using memory mapped files from .NET 4.0, but I am limited to using .NET 3.5, not higher versions.

Can someone help me with this?

Note. The XML nodes have some common attributes, a different number of attributes, and one identifier that I use for XPath queries.

+5
source share
5 answers

IF , you are sure that the performance comes from I / O, and you cannot change both applications, you really can do a little.

: RAM-. , - . , . , , -.

, : XML ( XmlDocument, ). , XmlReader, XPath, , XmlDocument, .

( ) : ( , , ) , , . , . , FileSystemWatcher - , / . , : / , XmlDocument ( ) . , ( XmlDocument XPath ).

EDIT: RAM-, Microsoft. , / . , DDK, ( ... ).

+3

XML . , . SQL Server Compact . XML, , XmlReader/XmlWriter, .

+2

, XML , , .

, , , .

+2

. , FileSystemWatcher, , .

, , , .


, , , .

+2

Try to open the file exclusively. Another application may crash, but if it does not crash, you will probably find out one thing: it cannot cause a large load of I / O in one cycle in the shared file, because all access attempts will be immediately triggered.

Hopefully he will just wait a second and try again, and this should work for you.

using (Stream iStream = File.Open("myfile.xml",
            FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
    ...
}
+1
source

All Articles