Spring Data Neo4j slow save

Good Morning everyone.

I'm having trouble saving entities, especially with relationships: basically the call takes over 1 second.

I'm using Spring Data Neo4j 6.3.5, and the graph is pretty simple, can find attach below.

This is the Java Class for Entities and Relationship:
Lot entity (The stock entity is equals)

@Id
@GeneratedValue(BSONIdGenerator.class)
private String id;

private String extId;

@Relationship(type = "LINK", direction = Relationship.Direction.OUTGOING)
public Set<LotLink> lotsIndexes;

@Relationship(type = "LINK", direction = Relationship.Direction.OUTGOING)
public Set<StockLink> stockIndexes;

@CreatedDate
private Long createdAt;

Link relationship

public class LotLink {

@RelationshipId  
private Long id;  

@Min(0)  
@Max(1)  
private Double splitIndex \= 1.0;  

@Min(0)  
@Max(1)  
private Double mergeIndex \= 1.0;  
    @TargetNode  
private Lot lot;  

}

This is the Postman call... it take more than 1 second to save a simple entity with a relationship.

filippocozzini_0-1668419545561.png

That's unexpected. Definitely nothing that we have observed in our testing. Can you give more insights into the storing logic you are calling?
So there is probably a Spring MVC Controller in place that passes this on to the business logic and renders the result as JSON, right? (Or Spring Data Rest)
Also there is your custom generator in place that might influence the behaviour.
In general this should happen in some ms instead of a second.

I’m using Spring WebFlux.

In this test i use a controller that autowire the Neo4J Lot Reactive Repository and save the object. I’m also try to remove the custom id generator but without success.

What could I send to help you investigate the issue?

Another observation: considering that the current situation is (:Lot)-[:Link]->(:Stock)

If I remove any outgoing relationships from the Stock (entity) class, the execution time goes from ~1s to ~700ms.

For more information, the controller has the @Transactional annotation

Have you tested this with just a single call? Or did you at least issue the request twice to a fresh started application?

I wonder because I can see the one second delay for the first contact with the database but on the follow up requests I get a reasonable 80ms for the call:

http://localhost:8080/create

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 167

{
"id": "9735f0df-5d84-4191-bb18-f2342fd09940",
"extId": "lot1",
"lotsIndexes": [
{
"id": 9,
"splitIndex": 1.0,
"mergeIndex": 1.0,
"lot": null
}
],
"stockIndexes": null,
"createdAt": null
}
Response file saved.
> 2022-11-15T174711.200.json

Response code: 200 (OK); Time: 80ms; Content length: 167 bytes

The initial time it takes is rooted in the Neo4j driver that will create the first connection on the first request. This action requires some amount of work.