neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

DidYouMean exceptions for some associations when an ActiveRel model is not defined #1524

Open tseleb opened 6 years ago

tseleb commented 6 years ago

We were noticing slow response times in some of our ENV and ran a profiling tool (ruby-prof) to determine where the time was being spent.

When we profiled SomeObject.all.with_associations(:content_type) we noticed a lot of exceptions coming from inside RelWrapping#wrapper: (Note the ~250 exceptions and that most of the time is spent inside of DidYouMean )

screen shot 2018-09-26 at 1 45 00 pm

From here we looked at #wrapper line 27 We thought based on this rails issue that maybe the end of the line should actually be rel_type.to_s.underscore.camelize since "camelize expects the string to be lowercase and with _". Also, looking at Neo4j::ActiveRel::Types::WRAPPED_CLASSES showed us :HAS_CONTENT_TYPE=>"HASContentType" ...where we think it should actually be HasContentType.

Once we made the above underscore change and reran the profiler we got: (Note only ~60 exceptions)

screen shot 2018-09-26 at 1 41 29 pm

We suspected it might be a load order issue because our production env is slow...but so far development has been consistently fast

... since we didn't have a HasContentType ActiveRel model defined in our application and as a result didn't have a model for it to preload?

So next, we created HasContentType as an ActiveRel model in our application. This time, when we tried profiling in the rails console, the HasContentType model loaded, there were no exceptions, and there was a much better performance time (took about 1/4 as long):

screen shot 2018-09-26 at 2 11 33 pm

Things we still don't understand...

What we are doing...

Currently, we are heading down the route of adding ActiveRel classes for all of our association types... but if anyone can point us in the right direction or has ideas of something else to try, we'd love to contribute back to this repo. But since adding underscore didn't fix all of the exceptions, we don't currently feel like we have a good enough handle on what is causing the issue.

Runtime information:

Neo4j database version: neo4j gem version: 9.3 neo4j-core gem version: 7.2.2