Welcome Guest, Not a member yet? Register   Sign In
Performance - XML parsing or database calls
#1

[eluser]dpgtfc[/eluser]
Right now, in my application, I have all of my navigation information stored in a database.

It is set up this way for group rights. (Three tables - navigation, groups, and navigation_groups (not the names used though). Each link belongs to a group, and when a user logs in, only links which belong in the groups a user does are displayed.

Anyway, right now, on every load of a page there is a database call. I think this would open my application up to a DOS attack, no? Even so, for performance issues, I have considered using XML. I will still store the data in a database, but when an admin makes a change to existing links, or creates a new one, it will make the changes to the database AND update the XML file.

So would there be a performance gain, or a drop, in my application?

*I need an XML file instead of a html file or include so that I can store it similarly as below*

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<navigation>
   &lt;link&gt;
      <permission_level>admin</permission_level>
      <name>User Management</name>
      <location>user/manage</location>
   &lt;/link&gt;
</navigation>
#2

[eluser]Jamie Rumbelow[/eluser]
You could write a JSON string to a file - it would be fast, lightweight and really easy to parse.
#3

[eluser]dpgtfc[/eluser]
[quote author="Jamie Rumbelow" date="1228596990"]You could write a JSON string to a file - it would be fast, lightweight and really easy to parse.[/quote]

Hmm, good idea, I never thought of JSON.
#4

[eluser]xwero[/eluser]
[quote author="dpgtfc" date="1228594456"]Anyway, right now, on every load of a page there is a database call. I think this would open my application up to a DOS attack, no? Even so, for performance issues, I have considered using XML.
[/quote]
You are describing a clear cut case of premature optimization.

There is nothing wrong with wanting to make as less database queries as possible but if you are afraid to get data out the database you better make static pages. And about the DOS attack, that is FUD. The database is not the only resource that is affected by a DOS attack.

About the performance, first benchmark your queries and you can always use cache if your site has a lot of traffic. Caching is much faster than parsing xml or json.
#5

[eluser]dpgtfc[/eluser]
[quote author="xwero" date="1228670633"]
You are describing a clear cut case of premature optimization.

[/quote]

You make this sound like a bad thing.

I want to learn the proper way of doing these things. The professional way that scales or decomposes gracefully. I don't program in the hardest way possible, I don't do things unless I think they are necessary.

I'm learning here, and learning how to do things in different ways is a good thing.

I'll look into caching.

Premature optimization... Yeah, lets wait until the last minute to make sure our site can handle 10k+ visitors at once.
#6

[eluser]Nick Husher[/eluser]
When to Optimize [wikipedia]

Donald Knuth famously said, "Premature optimization is the root of all evil." What he meant by that is that if you spend time optimizing your code at the beginning of your development cycle, you'll be spending a lot of time and energy to make your code less readable for only a minor performance benefit in the end.

What if your site never gets 10k users at once? You've been spending your time sharpening your code instead of changing your application structure to drive more users to your site. Optimization also usually brings with it a certain degree of unreadability (setting up the XML parser in PHP is pretty hefty, IIRC) and reduces your ability to change directions quickly if things aren't working out the way you planned.

If you're looking to avoid performance overhead, you could circumvent the JSON string altogether and write a new config file in PHP. All you have to do then is an @include or use CI's built-in configuration manager to load it. You might have to figure out how to write to it dynamically, but I'm sure there are solutions for doing such a thing. The big advantage of this method is that you're using PHP's own compiler to gain access to the data, so the performance overhead should be nil.
#7

[eluser]xwero[/eluser]
dpgtfc the situation you are describing is premature optimization because you are afraid to get menu data out of the database. I'm certain you will have to get much more data out of the database to display other content on the pages.

Caching is an unobtrusive way to improve the performance because you don't have to change the code you have written to get the content. If caching is insufficient you better upgrade your bandwidth instead of butchering your code.




Theme © iAndrew 2016 - Forum software by © MyBB