Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which one is faster reading an XML file or querying a database [closed]

I am designing a CMS in C# and need to decide where to save configuration settings for the site. Also considering defining my base html templates and then processing them server side to create the pages ahead of time.

So what is generally faster/less overhead for the server reading an XML file or querying that same information from a local database?

like image 770
Adrian Avatar asked Aug 03 '10 06:08

Adrian


People also ask

Which is faster reading from file or database?

In general the speed at which you can open a file for reading will be better than the speed at which you can establish a network connection. So for very simple operations, the filesystem is definitely faster. Filesystems will probably beat an RDBMS for raw read throughput too since there is less overhead.

Is XML faster than SQL?

You don't have as much admin overhead with XML files as you would with SQL Server. If the file is local, it will certainly be faster to read using direct file than networked SQL access. Far less between you and the data.

Why are we using XML instead of database?

1) When you have to interchange your data with others. XML is the "lingua franca" of the Web -- just about everyone can read and interpret it, unlike a database file. 2) When your data volume is small and you don't have to do complex queries against it.

Can you use a XML file as a database?

XML Database is used to store huge amount of information in the XML format. As the use of XML is increasing in every field, it is required to have a secured place to store the XML documents. The data stored in the database can be queried using XQuery, serialized, and exported into a desired format.


1 Answers

It seems unlikely to me that this will be a bottleneck in your code. How often are you planning on reading configuration settings? Configuration is typically fairly small, and read infrequently. There are more important things to consider about where and how to store it:

  • Bootstrapping: you can probably rely on your app having access to the local file system, and you can hard-code a configuration filename... but if all your configuration is in the database, where do you configure which database to talk to?

  • Ease of tweaking and deployment: editing a configuration file on the server by hand may be faster than making a change in the database... but if you have multiple servers, do you want to tweak a file on every one of them?

  • Simplicity of code reading/processing the configuration: what would your configuration look like? Is it naturally hierarchical? If so, XML is likely to be a good fit. If it's more like a set of name/value pairs, then a simple table is a good fit. Of course, you can store XML within a database - you don't have to tie the storage location and the storage format decisions together. Editing an XML document on the database may well be harder than either editing an XML file or changing individual values... but you can always make life easier with tools for this sort of thing.

like image 192
Jon Skeet Avatar answered Sep 28 '22 09:09

Jon Skeet