/** * Ignored b/c it doesn't assert anything, it just demonstrates the performance (and behavioral) * differences between {@link PersonService#getAllCurrentCoaches(java.util.Comparator)} and {@link * PersonService#getAllCurrentCoachesLite(java.util.Comparator)}. There are (at least) three * problems with the former... * * <ol> * <li>It lazily creates person records it hasn't encountered before, and * <li>It looks up {@link Person}s one-by-one, and * <li>Person lookups are just very expensive * </ol> * * <p>So if the total number of coaches returned from {@link * org.jasig.ssp.service.PersonAttributesService#getCoaches()} is large (anywhere into the 100s), * {@link PersonService#getAllCurrentCoaches(java.util.Comparator)} is unsuitable for invocation * in the request cycle, <em>even if all the referenced coaches have already been created as * {@link Person} records</em>. * * <p>{@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)} is faster, but partly * b/c it doesn't make any attempt to lazily create new {@link Person}s. So it doesn't run the * risk of exceptionally long runtimes when first invoked. But it does so at the cost of * potentially not returning a completely up-to-date view of all coaches. <a * href="https://issues.jasig.org/browse/SSP-470">SSP-470</a> combats this by moving the {@link * Person} creation into a background job. * * <p>This test demonstrates the performance gradient by causing {@link * org.jasig.ssp.service.PersonAttributesService#getCoaches()} to return 500 coach usernames the * {@link PersonService} hasn't seen before, then making a series of calls to the methods of * interest. At this writing (Nov 20, 2012), in an all-local development env, the numbers looked * like this (execution time in {@link org.jasig.ssp.service.PersonAttributesService#getCoaches()} * is effecively negiligible b/c this test stubs that service): * * <ol> * <li>{@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)} (returns 1 record): * 55ms * <li>{@link PersonService#getAllCurrentCoaches(java.util.Comparator)} (returns 501 records): * 29504ms * <li>{@link PersonService#getAllCurrentCoaches(java.util.Comparator)} (returns 501 records): * 15428ms * <li>{@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)} (returns 501 * records): 59ms * </ol> * * <p>Keep in mind again that {@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)} * doesn't make any of the lazy-creation promises of {@link * PersonService#getAllCurrentCoaches(java.util.Comparator)}, so the comparison isn't completely * fair. But the calls to the latter are sufficiently slow that it would be nice to find a way to * drop them both down... maybe through a combination of bulk db reads and writes and by * simplifying the object graph returned with all {@link Person} lookups. */ @Test @Ignore public void testLiteCoachLookupMuchFasterButPotentiallyIncomplete() { int externalCoachQuota = 500; Set<String> addedCoachUsernames = addCoachesToExternalDataAndAttributeService(externalCoachQuota); long started = new Date().getTime(); final PagingWrapper<CoachPersonLiteTO> allCoachesLite1 = personService.getAllCoachesLite(null); long ended = new Date().getTime(); System.out.println( "Lite Person lookups, no external Persons created yet: " + (ended - started) + "ms (" + allCoachesLite1.getResults() + " total records returned)"); started = new Date().getTime(); final SortedSet<Person> lazyCreatedCoaches1 = personService.getAllCurrentCoaches(null); ended = new Date().getTime(); System.out.println( "Full Person lookups, lazy Person record creation: " + (ended - started) + "ms (" + externalCoachQuota + " lazy records, " + lazyCreatedCoaches1.size() + " total records returned)"); started = new Date().getTime(); final SortedSet<Person> lazyCreatedCoaches2 = personService.getAllCurrentCoaches(null); ended = new Date().getTime(); System.out.println( "Full Person lookups, all Persons already created: " + (ended - started) + "ms (" + lazyCreatedCoaches2.size() + " total records returned)"); started = new Date().getTime(); final PagingWrapper<CoachPersonLiteTO> allCoachesLite2 = personService.getAllCoachesLite(null); ended = new Date().getTime(); System.out.println( "Lite Person lookups, all Persons already created: " + (ended - started) + "ms (" + allCoachesLite2.getResults() + " total records returned)"); }