Performance Tip

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

Performance Tip

Postby amcgilly » Thu Jun 18, 2009 10:47 pm

I work on a Servoy system that processes an ever-increasing volume of incoming and outgoing packets (currently around 3000 per hour and growing). I need to squeeze every drop of performance I can out of Servoy and the database (currently Sybase ASA)

I have learned that when adding new records into a table, sometimes the more elegant, readable code that Servoy allows carries a performance hit and you are better off resorting to code that is more efficient, though less elegant. Here's an example.

Let's say I have tables A and B, where B is the child of A (i.e. A to B is one-to-many).
I have a foundset called fsA on table A.
I have a relation called A_to_B.
I have a record selected in fsA and all I want to do is add a new child B record.

To insert the new child record I could do this:

Code: Select all
fsA.A_to_B.newRecord()
databaseManager.saveData()


This is convenient because it automatically assigns the foreign key(s) in my new B record, and it's also nice, compact, easy-to-understand code.

The problem is that it does more than I really need it to. In addition to inserting the new record it does the following:

1 - it builds the A_to_B related foundset, (i.e. it performs a select for all B records related to the current A record.)
2 - it resolves any aggregates for the A_to_B foundset (i.e. if I have any aggregations defined on table B, then it performs the required SQL to derive those for the A_to_B foundset)

In those situations I get better performance if I do this:

Code: Select all
    fsB = databaseManager.getFoundset('server_name','B')

    fsB.newRecord()
    fsB.foreign_key = foundset.pk_id
    databaseManager.saveData()


This does one and only one thing: it performs the insert.

So in general, when performance is a top priority, you want to be careful about making references to related foundsets in your code. Only refer to the related foundset if you really need the related records. Otherwise, find another way to code your process.

By the way, the way I verified all of this was by using the Performance Data page of the Admin Console. Anytime you want to test what SQL operations are being generated by a specfic section of your code, just go to the Performance Data page, clear the statistics that are there, run your code and then refresh the Performance Data page - there you will see exactly what queries your code just generated.

I welcome your comments/corrections/feedback.
Last edited by amcgilly on Fri Jun 19, 2009 7:05 pm, edited 2 times in total.
Adrian McGilly
Servoy Developer

Image
amcgilly
 
Posts: 375
Joined: Fri Dec 09, 2005 12:03 am
Location: San Francisco, CA

Re: Performance Tip

Postby ptalbot » Fri Jun 19, 2009 2:50 pm

Nice one Adrian!

Thanks!
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC


Return to How To

Who is online

Users browsing this forum: No registered users and 15 guests