The Artima Developer Community
Sponsored Link

Java Buzz Forum
Recursion gone wrong OR Too Much SQL

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Recursion gone wrong OR Too Much SQL Posted: Sep 19, 2006 5:53 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Recursion gone wrong OR Too Much SQL
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement

One action on the admin side of an application that I am working on was really slow. It would take up to 20 seconds to load.

This action is part of existing legacy software, so again I had to dig in and found the bad performer instantly.

The bad code was building a tree of categories, and worked just fine for tens of categories, or maybe even hundreds, but now the system had THOUSANDS of categories.

As I looked into the code that generated the tree, it didn't take a genius to work out the issue. The function was recursively calling itself as it got to each node in the tree (now build the subtree, now build its subtree, etc etc).

Recursion itself was not the problem, but each time the function was called it was running a new SQL query against the DB to get subtree information. This meant that many, many queries were running against the DB when one could be used.

By changing the action so that it:

  1. gets all of the category info first
  2. write out the tree using this info
  3. It went subsecond.

    Then we migrated from having it ask for the categories from the DB, to grabbing them from cache, and it became insignificant.

Read: Recursion gone wrong OR Too Much SQL

Topic: JRockit Certified Reference Platform for Eclipse! Previous Topic   Next Topic Topic: Don't Let Hibernate Steal Your Identity

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use