Hi all!
We had an internal competition that had its problem statements aligned with the problems that Mifos currently has. Prabaharan came up with this really good analysis and fix regarding re-architecting the current generate meeting schedule job. Please find his documentation, fix ( a patch on the trunk) and the jprobe test results and logs attached in this mail.
Also note the improvement in the performance of the batch job ( 1322 minutes -> 36 minutes).
Regards
Chandan
From: Gopalan, Prabaharan
Sent: Monday, November 23, 2009 1:04 PM
To: Thandavarayan, Parthasarathy; Rao, Chandan
Subject: RE: Code-a-thon - Fix and documentation
Okay.. sorry for the delay, because I imported the mifosFirstBatch.sql script, which took 2 hrs to import and another 22 hrs for the job (without fix) to complete in that BIIIG database. Here are the stats for the full database:
Time taken in minutes:
Pre-fix : 1322.7 (2009-11-21/19:52:53.078/IST WARN, org.mifos.framework.components.batchjobs, GenerateMeetingsForCustomerAndSavingsHelper, execute, 139, GenerateMeetingsForCustomerAndSavings ran in 79362901)
Post-fix: 36.53 (2009-11-23/11:45:13.055/IST WARN, org.mifos.framework.components.batchjobs, GenerateMeetingsForCustomerAndSavingsHelper, execute, 139, GenerateMeetingsForCustomerAndSavings ran in 2192621)
Performance Improved by 36.722 times
Attached is the java file that I modified for the fix. I have two log files (pre and post fixes) amounting to 11 Mb of size. Let me know a place where I can put it so that you can take a look.
Also attached is the documentation about the issue and the details of the fix. To apply the fix, replace the existing HolidayUtils.java with the new one and rebuild the project. I already provided the information about how to debug this application in Tomcat.
If you need further information, please let me know.
Thanks
Praba.
P.S: I haven’t done any architectural changes per se, but just replaced the code fragment that was causing the bottleneck.
Prabaharan Gopalan • Software Engineer • SunGard • Technology Services • Divyasree Chambers Langford Road Bangalore 560025 India
Tel +91-80-2222-0501 • Mobile +91-99165-48811 • www.sungard.com/sts
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
@keith: there is a hibernate caching mechanism in place right now..
which is configurable. I guess, the cache gets flushed after every x
accounts got processed. x is configurable. But that was not of much
help since the cache was growing every time there is query to get the
holidays. This makes any operation on the cache much slower than the
one before till it gets flushed. Actually, caching was the first thing
that occurred to me too.
On Dec 9, 4:59 pm, Keith Pierce <krp0...@gmail.com> wrote:
> Very nice analysis, Chandan, and a clever fix with dramatic results.
>
> Did you consider using Hibernate's caching mechanisms? If that mechanism
> resulted in similar improvement in performance, it would have the advantage
> of being completely transparent to the application code. Another advantage
> is that the cache can be configured to expire and reload periodically in an
> automated way.
>
> Keith Pierce
>
> On Wed, Dec 9, 2009 at 12:48 AM, <Chandan....@sungard.com> wrote:
> > Hi all!
>
> > We had an internal competition that had its problem statements aligned with
> > the problems that Mifos currently has. Prabaharan came up with this really
> > good analysis and fix regarding re-architecting the current generate
> > meeting schedule job. Please find his documentation, fix ( a patch on the
> > trunk) and the jprobe test results and logs attached in this mail.
>
> > Also note the improvement in the performance of the batch job ( 1322
> > minutes -> 36 minutes).
>
> > Regards
>
> > Chandan
>
> > *From:* Gopalan, Prabaharan
> > *Sent:* Monday, November 23, 2009 1:04 PM
> > *To:* Thandavarayan, Parthasarathy; Rao, Chandan
> > *Subject:* RE: Code-a-thon - Fix and documentation
> > *Prabaharan Gopalan* • Software Engineer • SunGard • Technology Services •
I am no Hibernate expert but I think the base of having ORM framework
like Hibernate is to provide caching so that we can avoid creating
static caching like in the patch.
AFAIR, Adam Monsen also raised this point that, it is be possible that
using hibernate (Hibernate caching configuration, Hibernate batch
queries enabled) we can speed up things in Batch job and this example
(Analysis from Prabaharan) showshow dramatic impact it could be.
Chandan, can you or Prabaharan create a Improvement issue type at
http://mifosforge.jira.com ?
Thanks,
Udai Gupta
I should have been more clearer.. here is the rephrased reply:
Hibernate has a caching mechanism and that was being used previously
in the code. But that was not of much help since the cache was growing
every time there is query to get the holidays. This makes any
operation on the cache much slower than the one before till it gets
flushed. I tried to tweak the caching part of it, but the problem was
elsewhere. so i was forced to look for alternatives.. and that led me
to the holiday retrieval which was being done for every meeting that
was generated which we can avoid by storing (java object caching) it
locally..
I hope that is clear ..
I just missed your last mail before shooting mine :)
I didn't mean to argue. I completely agree with your analysis and fix,
its just I am more concern about the other places in batch job as you
mentioned "elsewhere".
> I tried to tweak the caching part of it, but the problem was elsewhere.
It was just my opinion. I really appreciate what you have done.
Creating a Improvement issue type at http://mifosforge.jira.com will
help us to track down the issue and fix that you have raised.
Thanks,
Udai
Batch Jobs can have this code because Hibernate caching is a bigger
issue (probably design related) and to resolve that I think we might
need to re-implement the batch jobs.
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-cache
http://ehcache.org/documentation/hibernate.html
I just noticed in hibernate configurations Mifos is using
HashtableCacheProvider, where in the first reference its advised that
HashtableCacheProvider should not be used in production (I haven't dig
more about that).
We have ehcache configuration file in
application/src/main/resources/org.mifos.config.resources.
Probably second level caching for Entities and queries might give us
performance enhancement at various other places in Mifos.
Udai
I am really sorry if i was confusing in my previous post ( even now i
am little concerned whether this was clear enough :-) ) And sorry
again for the long post...
On Dec 9, 9:35 pm, Udai Gupta <mailt...@gmail.com> wrote:
> some references
>
> http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performanc...http://ehcache.org/documentation/hibernate.html
I have one suggestion for the patch before we commit it to the trunk:
don't use a static member on HolidayUtils. If the cache is only for
GenerateMeetingsForCustomerAndSavingsHelper, make that batch job
initialize the cache and clear it (in a finally block) upon
completion.
In the long run, we'd much prefer if there were some way to leverage
existing cache infrastructure. I believe we already have ehcache
installed/configured and Udai mentioned that Hibernate has a second-
level cache in addition to the session cache. In general, caching
should be something that is configured once and would "just work", but
I understand and agree with Udai that batch jobs typically need to
behave differently than the normal running application (otherwise why
would we have batch jobs?).
So if we can't do it with Hibernate, have you thought of how we might
leave management of this cache up to ehcache?
http://mifosforge.jira.com/browse/MIFOS-2623
On Dec 10, 11:21 am, John Woodlock <john.woodl...@gmail.com> wrote:
> Prabaharan can correct me if I'm wrong but the current change made will
> impact any piece of functionality that regenerates schedules.
>
> If memory serves me correctly, in addition, to this
> "GenerateMeetingsForCustomerAndSavingsTask" batch job, it also impacts
> "RegenerateScheduleTask" batch job as well as loan disbursals (made after
> the anticipated disbursement date).
>
> This change may also give some impetus to completely removing these two
> batch jobs mentioned above during Gazelle C for example (if scalability is a
> key focus) and catering for them within the operational system (unless there
> is something other non-performance reason they need to run just after
> midnight).
>
> John
>
> On Thu, Dec 10, 2009 at 7:15 AM, Adam Monsen <hair...@gmail.com> wrote:
>
> > If the cache is only for
> > GenerateMeetingsForCustomerAndSavingsHelper, make that batch job
> > initialize the cache and clear it (in a finally block) upon
> > completion.
>
>
>
john said:
>> This change may also give some impetus to completely removing these two batch jobs
>> mentioned above during Gazelle C for example (if scalability is a key focus) and catering for >> them within the operational system (unless there is something other non-performance
>> reason they need to run just after midnight).
I completely agree with this. The core problem is the existence of
these batch jobs in the first place which appears to be a 'crude
approach' to the problem of schedules and meetings. The need for
batching this operation disappears when the logic for creating
meetings/schedules is pushed back into the application domain.
Removing the batch jobs would be a great simplification of the system
and would also ease setup and operation of the application (moving
towards mifos as a platform, would be ideal not to need this batch
jobs); all good reasons for a release of its own.
On Hibernate Second Level cache talk:
I am curious as to what exactly you were going to cache here. I wasn't
aware that we were using 'second level cache' in the application, i
thought it was only the 'session cache'. Its seems then that EHCache
is our second level cache provider and most of my experience has being
using this only for 'read only' or 'Non strict read/write' caching
strategy for which the second level cache is very good (so data that
is only read and never updated e.g. seed data, or seldom updated with
non strict strategy), with regards the other caching strategies
(read/write & Transactional) I believe that these are a little
trickier to work with, you have to be careful and thoroughly test the
behaviour to verify it is doing what you think it should be doing.
KeithW
Hi john
I have updated GK regarding these developments. I am trying to see if they can test this on their test server. I will compile and provide them a holiday utils class file that will have the new code in it.
Regards
Chandan
Chandan,
Please do not do this. We strongly discourage customers from making
changes like this to production and staging systems.
I will respond off list to explain this further.
-adam
--
Adam Feuer <adamf at pobox dot com>
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
Just checking in. Has any progress been made on this?
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Prabaharan, thanks for following up!
Given the huge potential performance increase, I propose we go ahead
with your original patch ( http://tinyurl.com/y8oybpj ), but just
include a warning log message if the static cache of holidays ends up
getting to be large (say, > 100 or so). The warning could be something
like: "holiday cache is too large. Consider using a caching framework
like ehcache instead".
Just on this, John and myself have talked about this and its on our
list of quick wins:
http://www.mifos.org/developers/wiki/ScalabilityAndArchitectureDiscussion#batch-jobs
Prabaharan did a good analysis of this and correctly identified that
it was the 'Holidays' that were causing a lot of the problems with the
slowness of this batch job. While Prabaharan's patch will work, but
having looked at this problem today I would prefer to refactor this
area towards the arcitectural roadmap rather than place the static map
for retaining holidays. The problem area revolves around the
HolidayUtils class and the code that uses all its methods. see
MeetingBO.getAllDates(int o).
Regards,
KeithW.
> ------------------------------------------------------------------------------
> SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
> Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
> http://p.sf.net/sfu/solaris-dev2dev
>
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev