don't click here

Mega Performance Improvement in Submissions


    Print

Author Topic: Mega Performance Improvement in Submissions  (Read 4990 times)

0 Members and 1 Guest are viewing this topic.

Offline GerbilSoft

  • Architect of the Matrix
  • TSC Profile
  • linux firefox
  • Posts: 719
  • RickRotate'd.
    • View Profile
Mega Performance Improvement in Submissions
« on: December 22, 2007, 04:55:46 pm »
For those of you who were here back in 2004 and 2005, you may remember how the Submissions page took forever to confirm a page of stats. As I recall, it took over 1,000 database calls to confirm a single stat! Rolken optimized that some time ago, but it still took quite a while if you submitted over 50 stats at once. Last night, I looked over the processing code to figure out why it was taking so long. It turns out that there are (were) two major performance problems:

1. When inserting queue updates, the script built a long string using the PHP concatenation operator and then sent it to the database. This seems like it's more efficient, since it only does one query, but it's actually worse because the database has to process a long string.

2. The queue system checked the temporary queue for duplicates before adding new stats. The checking system was linear; that is, it checked all elements in the array to see if there were any duplicates. This works fine for a few stats, but the time grows exponentially as more stats are added to the list.

How I fixed both of these:

1. Instead of building a huge string, use prepared statements. This makes it so the script only sends the query once, and then it simply sends the data. The data is sent in binary form, so it's much faster for the database to process. I've converted the biggest user of this method so far, and it knocked off around 20 seconds (~120s vs. ~140s) for processing 100 suspended stats. There's still some more functions that are using the old concatenation method that I need to convert later.

2. Maintain two arrays; one with the original data, and one as an indexing array. This increases memory usage, but it changes execution time from exponential to linear.

Overall: TSC should now be able to confirm your submissions faster. :)

Offline FoxLuc

Re: Mega Performance Improvement in Submissions
« Reply #1 on: December 22, 2007, 07:08:44 pm »
I like your guts Gerbil.
The only thing that can stop us is flat tire.

    Print
 

Hits: 533 | Hits This Month: 3 | DB Calls: 8 | Mem Usage: 1.03 MB | Time: 0.07s | Printable

The Sonic Center v3.9
Copyright 2003-2011 by The Sonic Center Team.