• About

Day 2 Day Dynamics

~ Experiences of a working AX developer

Day 2 Day Dynamics

Tag Archives: AX Development

Minimizing Database Calls

01 Monday Feb 2016

Posted by John Hagler in X++

≈ Leave a comment

Tags

AX, AX 2012, AX Best Practices, AX Database, AX Development, Dynamics AX, Performance, Tuning

I have been focusing a lot of attention on performance tuning AX over the last year.  The company I work for has now been live on AX 2012 R2 for about a year and a half and we’ve spent a lot of effort tuning indexes and re-writing code and processes to speed up our system.  Spending so much time thinking about performance has caused me to change the way I write and fix code so I figured I would share.

Outside of making sure you have good indexes for your tables, the biggest offender I’ve found for slow processes is unnecessary database calls.  I see it and have been guilty of writing it in code all the time.  You have a process that loops through records, evaluates some conditions, grabs related data if necessary and then performs some action.  The offender in this scenario is “grabs related date if necessary”.

It is really easy to write a basic query to start off with and then, in the middle of your process, grab more data.  AX 2012 makes it easy for you with Table::find() methods and by having the CreateNavigationPropertyMethods property on a table relation.  This allows a developer to grab a related table from an existing table buffer using a method call that matches the relation (e.g CustTable.DirPartyTable_FK()).  While this is incredibly useful, the danger with this approach is that it adds another database call to the process.

DatabaseCallJob

Examine the job above.  I have 2 while select statements that loop through the same number of records.  I have used different ranges so I could show times for cached and non-cached results.  The first loop grabs the project records and then during processing makes 2 more database calls to get the CustTable and then the DirPartyTable.  The second loop uses joins and a field list to minimize both the amount of data returned and the number of database calls.

I ran this process twice.  The infolog shows that the first loop took 5 seconds to run and the second loop took 1 second to run.  The second time I ran this process the first loop fell to 3 seconds because of database caching.  This means that the first loop takes 5 times longer to run when it’s calling the database and 3 times longer when its reading from the cache (a precision of seconds is probably minimizing this difference).  5 seconds doesn’t seem like a long time to process over 1100 records but there are a few things to consider.  This process isn’t doing anything but grabbing the records and this job was run in a stand-alone development environment.  The client, AOS and database are all on the same server and there is no one else using it except for me.  Imagine how much longer this could be if there were lots of users running processes in the system or if the components were separate and the network happened to be slow.

Each database call can add up to 2 remote procedure calls depending on where the code is running.  In this instance, my job is running on the client so the number of RPC’s is twice the number of database calls (1 from client to AOS and 1 from AOS to database).  The first loop has 2 RPCs for the while select, and then 2 (number of calls) X 2 (client and server) X 1169 (number of records) for a total of 4,678 RPCs and 2,339 database calls.  The second loop has 2 RPCs and 1 database call and the potential to give you just as much data as the first loop.  That’s a pretty crazy difference!

I now write a lot more X++ pseudo-SQL with joins when writing new code and changing existing processes.  The amount of time that can be saved during runtime far outweighs the extra time it takes to plan out your processes to grab all of the data that is needed the first time.

 

Import-AXXPO custom PowerShell function

12 Tuesday May 2015

Posted by John Hagler in Powershell

≈ 3 Comments

Tags

Automation, AX, AX 2012, AX Development, AX Import, Build Scripts, Dynamics AX, PowerShell, XPO

The Import-AXXPO custom PowerShell function allows you to automate the importing of .xpo files.  It is going to look very familiar to people who have read some of my other functions as it follows the same format as Compile-AXCIL and Sync-AXDB.

The Import-AXXPO function takes between 2 and 9 parameters:

  • ConfigPath (Client configuration for the chosen AX environment)
  • LogFile (The value defaults to the temp folder but can be overridden if desired)
  • TimeOut (The value defaults to 20 minutes but can be overridden if desired)
  • ImportFile (The .xpo file to import)
  • Model (The AX model to open in)
  • SMTPServer (SMTP server to use to send the email)
  • MailMsg (Net.Mail.MailMessage object used to send the email)
  • AXVersion (The AX version.  It defaults to 6.)
  • VariablePath (Path to a file used to default the parameters/variables)

I use the VariablePath parameter the same way that I do in the other functions I’ve posted that use it.  This function can be found in Codeplex.  The steps of this function are:

  • Load the variables if a VariablePath parameter is used
  • Validate the ImportFile parameter location
  • Get the AX environment info using Get-AXConfig
  • Get the CompileIL AX AutoRun xml using the Get-AXAutoRunXML function
  • Call the Start-AXAutoRun function to import the .xpo

Some things to consider with this function.  Where an .xpo is imported is controlled by 3 things.  The configuration file used to open AX will control what layer the .xpo is imported into.  The model is controlled by either the Model parameter or the user option “Startup model” (Tools -> Options -> Development -> Startup model).  This value is stored per user and per layer so make sure you have this value set up in every AX environment that you will be importing .xpos in if you don’t use the Model parameter.

This function should also only be run on the AOS server.  It has been tested using AX 2012 R2 CU7 but should also work for R3.

Follow Day 2 Day Dynamics on WordPress.com

Day 2 Day Dynamics

  • RSS - Posts
  • RSS - Comments

Follow me on Twitter

My Tweets

Recent Posts

  • Minimizing Database Calls
  • Push-AXModel custom PowerShell function
  • Clean-AXModel custom PowerShell function
  • Get-AXTFSCombinedXpo custom PowerShell Function
  • Refresh-AXAifPort custom PowerShell function

Archives

  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015

John Hagler

John Hagler

John Hagler

I am the Dynamics AX Technical Architect at Dealer.com. I have been working with AX since Sep. 2006, starting with Axapta 3.0. I have worked as both a VAR and an AX customer.

View Full Profile →

Blog at WordPress.com.

  • Follow Following
    • Day 2 Day Dynamics
    • Already have a WordPress.com account? Log in now.
    • Day 2 Day Dynamics
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...