The current default of "open session in view" for Spring Data Neo4j hurts performance in cluster scenarios.
By opening the session on the request, the session will be a general purpose session ("read write") and always go to the leader of a cluster, leaving all followers and read replicas unused. I have written down an analysis of the problem here Spring Data Neo4j, Neo4j-OGM and OSIV.
Neo4j-OGM doesn't have the issue of lazy loading and keeping the session up and running through the request only helps caching inside OGM.
If such a change is unappropriated for 2.3, I would like to see a better warning, for example
logger.warn("spring.data.neo4j.open-in-view is enabled by default."
+ "Therefore, database queries may be performed during view "
+ "rendering. It also prevent's chosing anything else than the leader in a cluster scenario. Explicitly configure "
+ "spring.data.neo4j.open-in-view to disable this warning");
Or, the best might even check if one or more bolt+routing
respectively neo4j://
Uris have been configured and than according to that, choose a sane default.
So, I basically see three options:
- Change the warning to be more drastic or
- Change the default or
- Change the default conditionally when there's one or more
bolt+routing://
orneo4j://
uris or more than onebolt://
URI.
I could implement each one of them, but wanted to hear your opinion on that.
Comment From: snicoll
@michael-simons thanks for the report and such a change for the reason you've described seems appropriate to me.
I don't really have an opinion besides the fact that the last option makes it harder to resonate what the default value of the flag is. If we keep a boolean
flag, I'd rather keep a straight true/false
rather than true
if the transport is configured in a certain way.
My vote would go for #2. Flagging for team attention to see what the rest of the team thinks.
Comment From: michael-simons
Completely agree with you on this one.
Comment From: wilkinsona
Neo4j-OGM doesn't have the issue of lazy loading
In that case, +1 for changing the default. The pattern's only really of value when it reduces the learning curve of lazy loading problems. Without that problem to solve, it feels like a bad default to me.