Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #98 - Reuse Calendar for creating ServiceDate in WSFBlockResolutionStrategy #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

skjolber
Copy link

@skjolber skjolber commented Mar 9, 2018

Summary:

Reuse Calendar in WSFBlockResolutionStrategy

Expected behavior:

Constructs ServiceDate using another constructor.

Please make sure these boxes are checked before submitting your pull request - thanks!

  • [ x] Run the unit tests with mvn test to make sure you didn't break anything
  • [ x] Format the title like "Fix #<issue_number> - short description of fix and changes"
  • [x ] Linked all relevant issues

@CLAassistant
Copy link

CLAassistant commented Mar 9, 2018

CLA assistant check
All committers have signed the CLA.

@skjolber
Copy link
Author

@barbeau any hope for merging this?

@barbeau
Copy link
Member

barbeau commented Jun 25, 2018

@skjolber Thanks for contributing this! I think so, but I'm not the best one to review this. I'm adding @sheldonabrown and @sdjacobs to the thread to get their reviews for possible merge.

@sdjacobs
Copy link
Contributor

@skjolber, could you give us some more info on why you made this change? To me, it looks like it's essentially nonfunctional - it doesn't break anything, but I'm not sure what it adds. The main performance issue in this code is that it makes tons and tons of API calls to the ferry schedule API; I really can't imagine Calendar object creation is a bottleneck. Is it?

Also, just out of curiosity, why are you in this part of the code? I thought this was a Seattle-specific issue. Are there ferry services in Norway that use the same API?

@skjolber
Copy link
Author

This is a performance improvement. Creating calendars appeared to be called relatively frequently / costly when using a profiler. I can't find the exact results, but I believe the use-case was search.

OpenTripPlanner uses an onebusaway dependency so that is the relation.

@@ -151,8 +151,8 @@ private void setBlockIdsFromSchedResponse(SchedResponse resp) {
String arrive = stc.getArrivingTerminalID().toString();

for (SchedTime sched : schedTime(stc)) {
long time = ts(sched.getDepartingTime());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdjacobs I think the optimization is here - if you look at private long ts(XMLGregorianCalendar xgc) {...} method, within that method it instantiates a GregorianCalendar to get the time, but then throws it away and just returns a long. Then, in resolve() another Calendar object is instantiated again. This cuts out the instatiation in resolve() by passing in an existing instance of Calendar into resolve().

@skjolber Did I get that right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barbeau Yes.

@sdjacobs
Copy link
Contributor

OTP only uses the onebusaway-gtfs submodule, which is the GTFS model classes.

WSFBlockResolutionStrategy is a strategy for onebusaway-gtfs-transformer, a different submodule which is used to apply defined transformations to a GTFS feed. More information on usage here. In particular, this strategy queries the Washington State Ferry API for schedule information, in order to add blocks to the GTFS, as the official provided WSF GTFS doesn't include blocks.

I don't think this change will provide a performance improvement, since the performance of this strategy is totally dominated by the latency of the thousands of requests it makes to the WSF API, rather than Calendar creation. (It certainly won't affect OTP's performance, since OTP doesn't use this submodule.)

I don't have a problem with the change per se, I just want to make sure everyone's clear on what it does (or does not do).

@skjolber
Copy link
Author

@sdjacobs I agree this is just a small step in improving the performance. The overall picture seems to be that a lot of garbage is created, triggering (costly) garbage collection relatively often. This calendar reuse is just a low-hanging fruit.

@skjolber
Copy link
Author

Ah, there was also an issue with some more details: #98

@sheldonabrown
Copy link
Member

To reiterate, this pull request almost certainly has nothing to do with the performance/memory issues you are experiencing. This code path is very specific to one integration strategy that you would not be using (please tell me if that's not the case).

As Simon said, the effort is welcome, but this change will not have the effect you intend. In fact, it should have no affect since it lives outside the typical code path.

@skjolber
Copy link
Author

skjolber commented Jun 26, 2018

Look, I cant really remember / locate the exact benchmark and code path, so I suggest reviewing this PR as a performance improvement as-is.

@sheldonabrown
Copy link
Member

Yes, I totally appreciate that, and we will likely accept the pull request. But we need to be clear it will have no affect on anything you are likely doing. And it will have no affect on the actual strategy as it is I/O bound with respect to webservice latency. So that is to say this PR represents a "non-functional change"

@skjolber
Copy link
Author

Ok, thank you for pointing that out again. I'll make sure to describe issues / PRs better in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants