Speed up your execution performance by using SysGlobalCaches

 




Ever come across a situation where you needed to 

a. Using a multi-threaded batch to import a journal header and lines, from a staging table. The table already contains the Journal Ids which you need to assign to the header and allocate the lines under that header.

b. You need to continuously check after each line being imported, if the journal with the Id has been created. If not, it will create the header and create the lines under it;  If yes, it will directly create the lines for the header (Find or create).

c. As you could rightly guess, this architecture has an inherent sluggishness associated with it -- each time you keep on checking if the header has been created or not, it does mean a lot of performance effects, as a consequence. Also as you can understand it's a multithreaded code, which means each thread has no direct relation with the other -- which does mean there is no way I can talk between the threads/pass on any information.

SysGlobalCaches to the rescue:

I personally prefer to use SysGlobalCaches for all such situations. Imagine using a Map and you are stacking up the journal number and generated Journal header record in it.

Map journalMapInfo = new Map(Types::string, Types::Record); 

Please note, that you need to do this at the child task class of the batch [for example the child batch class which in turn takes up each task to process things further (e.g.: finding and creating journal header and lines)]. 

SysGlobalCache journalGlobalCache globalCache = appl.globalCache();

Check if journalMapInfo value is already in the globalcache object:

if (appl.globalCache().isSet(owner, key) == true)

{

    journalMapInfo  = 

    appl.globalCache().get(owner, key);

    ledgerJournalTable = journalMapInfo.Lookup(JournalMapInfo, journalId);

}

if not, then here you are assigning the journal Id and record generated:

journalMapInfo.insert(journalNum, ledgerJournalTable);

And then you store the map in the globalcache:

journalGlobalCache.set(owner, key, journalMapInfo, false);

Note the last variable: it indicates that purposely you are setting the content of the global cache as false, so that it's not flushed, between the sessions.

This can result in limiting the searching of the JournalTable between different errands of the parallel tasks, by simply letting the system lookup the journal records across a shared global cache, instead of querying the database, recursively.  
 

Comments

  1. Can you please give us a code snippest? (the small and working code snippest which we can refere and understand the actual implementation of sysGlobalCache)

    ReplyDelete

Post a Comment

Popular posts from this blog

X++ : mistakes which developers commit the most

Make your menu items visible on main menu, conditionally,, using this cool feature of D365FO