Performance testing

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Moderator: edward

Performance testing

Postby martinh on Mon Nov 17, 2008 4:18 pm

Hello,

Does someone know if there is a way to monitor what Servoy method are called how many times and how many ms it took to finish the method (something like the performance data in the application server, but then for methods and not for queries)
If something like that exsist, it would help me to find performance issues in the javascript.
Because when you step through your coding with the debugger you see that all works correct, but you can't see if there is some performance issue.

Martin
Martin
Globis N.V.
Aalst - Belgium
http://www.globis.be
------------------------------------------------
Servoy Developer
Version 4.1.5
Java version 1.6 update 17 (Windows Vista)
Database SQL Server 2005
User avatar
martinh
 
Posts: 624
Joined: Wed May 09, 2007 4:34 pm
Location: Belgium

Re: Performance testing

Postby ngervasi on Mon Nov 17, 2008 5:04 pm

You can do it yourself by writing a timestamp at the method start and another one at the method end. You could write to a logfile or directly to a log table, in the last case you could also have a calculation to show the length and a nice GUI to see the results.
ngervasi
 
Posts: 1009
Joined: Tue Dec 21, 2004 11:47 am
Location: Arezzo, Italy

Re: Performance testing

Postby david on Mon Nov 17, 2008 5:09 pm

Another output option is the status bar -- immediate feedback. Great for smart client testing on dodgy connections.

Picture 22.png
Picture 22.png (8 KiB) Viewed 383 times
David Workman
Data Mosaic

AKA "The iPad Thread Killer"
User avatar
david
 
Posts: 820
Joined: Thu Apr 24, 2003 3:18 pm
Location: Washington, D.C.

Re: Performance testing

Postby agiletortoise on Mon Nov 17, 2008 5:27 pm

Below is a profiling method I use in my testing. It's a better approach to my mind because it requires no changes to your original code to track the timestamps, etc.

Code: Select all
function profile_global_method()
{
  var orig = arguments[0];
  var newName = orig + '_orig';

  if(typeof globals[newName] == 'function')
    globals[orig] = globals[newName];
  globals[newName] = globals[orig];

  var pStart;
  var before = function() { pStart = new Date(); };
  var after = function() { application.output(orig + ":" + (new Date() - pStart)); };

  var repl = function() {
  switch(typeof before)
  {
    case 'string' : eval(before); break;
    case 'function' : before(); break;
  }
  var result = globals[newName].apply(this, arguments);
  switch(typeof after)
  {
    case 'string' : eval(after); break;
    case 'function' : after(); break;
  }
  return result;
  }
  globals[orig] = repl;
}


This takes the name of a global method. You call it from somewhere else, typically in an "enter profiler mode" method somewhere that will call it repeated for the different methods you want to watch. It aliases the original global method in the runtime and replaces it with a version that tracks profiling ticks and outputs them to the console. No further modifications to your original code are required.

Once you do this, everytime the method is called you get "methodName:[ticks]" to the console after it runs. Clearly you could modify this to track that in a db, keep counts of the number of times particular methods are called, etc.

greg.
Greg Pierce
Agile Tortoise
SAN Developer
http://www.agiletortoise.com
User avatar
agiletortoise
 
Posts: 285
Joined: Wed Oct 12, 2005 2:26 pm
Location: Texas, USA

Re: Performance testing

Postby andrew2pinsky on Tue Nov 18, 2008 11:06 am

agiletortoise wrote:This takes the name of a global method. You call it from somewhere else, typically in an "enter profiler mode" method somewhere that will call it repeated for the different methods you want to watch. It aliases the original global method in the runtime and replaces it with a version that tracks profiling ticks and outputs them to the console. No further modifications to your original code are required.


Thanks Greg for sharing this,

Can you please, write a little bit about the use of this method, profile_global_method(). I am little bit confused how to use this Method to check for performance Issue in my code.

I have added this method, profile_global_method() to my globals. Let's I have method executeCode(), and I would like to check the time it takes to finish executing the method. How can I do that?

I tried
Code: Select all
globals.profile_global_method(globals.executeCode);
But, it won't work...

Is there any additional set up required?

Thanks in advance.
Reagrds Andrew,
andrew2pinsky
 
Posts: 10
Joined: Tue Nov 18, 2008 8:07 am

Re: Performance testing

Postby martinh on Tue Nov 18, 2008 11:25 am

andrew2pinsky wrote:I am little bit confused how to use this Method to check for performance Issue in my code.


Join the club! I was confused as well.
But after discussing with a colleague we have found out how it works.

And we must say thanks very much Greg for this example. For us this is really high level Javascript.

This is what we did to use it:

Code: Select all
for (var i = 0; i < globals.allmethods.length; i++){
   if (globals.allmethods[i] != 'profile_global_method')
      globals.profile_global_method(globals.allmethods[i]);
}


Now all global methods are profiled without any change! By the way, this only works in Servoy 4. Not in 3.5.x
Martin
Globis N.V.
Aalst - Belgium
http://www.globis.be
------------------------------------------------
Servoy Developer
Version 4.1.5
Java version 1.6 update 17 (Windows Vista)
Database SQL Server 2005
User avatar
martinh
 
Posts: 624
Joined: Wed May 09, 2007 4:34 pm
Location: Belgium

Re: Performance testing

Postby andrew2pinsky on Tue Nov 18, 2008 11:39 am

Hi Marteen,

Thanks for your reply.

After, profiling my global method, by,

Code: Select all
globals.profile_global_method(globals.executeCode);


When, I am executing the method, executeCode(), it simply go on executing. It doesn't displaying any console output....

Am I missing something????
Reagrds Andrew,
andrew2pinsky
 
Posts: 10
Joined: Tue Nov 18, 2008 8:07 am

Re: Performance testing

Postby martinh on Tue Nov 18, 2008 11:45 am

Hi Andrew,

You should use it like this:

Code: Select all
globals.profile_global_method('executeCode');


I made the same error when I tested the method.

Martin
Martin
Globis N.V.
Aalst - Belgium
http://www.globis.be
------------------------------------------------
Servoy Developer
Version 4.1.5
Java version 1.6 update 17 (Windows Vista)
Database SQL Server 2005
User avatar
martinh
 
Posts: 624
Joined: Wed May 09, 2007 4:34 pm
Location: Belgium

Re: Performance testing

Postby andrew2pinsky on Tue Nov 18, 2008 11:49 am

martinh wrote:Hi Andrew,

You should use it like this:

Code: Select all
globals.profile_global_method('executeCode');


I made the same error when I tested the method.

Martin


Hi Marteen,

Thanks....I got it....Now it is working.. :D

Thanks a lot for the same.
Reagrds Andrew,
andrew2pinsky
 
Posts: 10
Joined: Tue Nov 18, 2008 8:07 am

Re: Performance testing

Postby agiletortoise on Tue Nov 18, 2008 3:47 pm

Here's an improved version which tracks profile data in a global variable $profileData, counts the number of times a method was executed, and outputs to the console the "START" and "END" points of each method call.
Code: Select all
function profile_global_method()
{
  var orig = arguments[0];
  var newName = orig + '_orig';

  if(typeof globals[newName] == 'function') globals[orig] = globals[newName];
  globals[newName] = globals[orig];

  if(typeof $profileData == 'undefined') $profileData = { };
  if(typeof $profileData[orig] == 'undefined') $profileData[orig] = {count:0, lastStart:null, lastEnd:null, ticks:0};
 
  var before = function() {
        $profileData[orig].count = $profileData[orig].count + 1;
        $profileData[orig].lastStart = new Date();
        application.output("START | globals." + orig + " | count: " + $profileData[orig].count);
  };
  var after = function() {
        $profileData[orig].lastEnd = new Date();
        $profileData[orig].ticks = $profileData[orig].lastEnd - $profileData[orig].lastStart;
        application.output('END   | globals.' + orig + " | count: " + $profileData[orig].count + ", ticks: " + $profileData[orig].ticks);
  };

  var repl = function() {
      before();
     var result = globals[newName].apply(this, arguments);
      after();
     return result;
  }
  globals[orig] = repl;
}


The output you get in the console will look like the below. This example is one call to 'test2' which is a method which also calls 'test1' from inside it.

Code: Select all
START | globals.test2 | count: 6
START | globals.test1 | count: 7
END   | globals.test1 | count: 7, ticks: 10
END   | globals.test2 | count: 6, ticks: 50
Greg Pierce
Agile Tortoise
SAN Developer
http://www.agiletortoise.com
User avatar
agiletortoise
 
Posts: 285
Joined: Wed Oct 12, 2005 2:26 pm
Location: Texas, USA

Re: Performance testing

Postby mboegem on Tue Nov 18, 2008 4:17 pm

Great code, thnkx Greg!
_____________________
Marc Boegem
Newbase bv
SAN Partner / Servoy Developer
_____________________
Version: 5.0.1 - build 861
Java version 1.6.0_17 (Windows XP)
SVN w/ Subversive Eclipse plugin
Sybase SQL Anywhere 11.0.1
User avatar
mboegem
 
Posts: 304
Joined: Sun Oct 14, 2007 12:34 pm
Location: Amsterdam, The Netherlands

Re: Performance testing

Postby ars on Wed Nov 19, 2008 6:13 am

agiletortoise wrote:Here's an improved version...


Great. Thanks Greg. :D
Arup Ranjan Sahoo
http://www.mindfiresolutions.com
SAN Developer
User avatar
ars
 
Posts: 204
Joined: Thu Jun 28, 2007 1:04 pm
Location: India


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 2 guests