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

Share session between HTTP request in web apis / web applications #173

Open
vzenix opened this issue Apr 5, 2023 · 11 comments
Open

Share session between HTTP request in web apis / web applications #173

vzenix opened this issue Apr 5, 2023 · 11 comments
Labels
enhancement New feature or request

Comments

@vzenix
Copy link

vzenix commented Apr 5, 2023

Is your feature request related to a problem? Please describe.
I have complex queries, the first execution in a session it consume to much time, but next time execute it fast in the same HTTP Request, but when y start a new HTTP, the library create a new session, and again the query work slow, I have this time for example in complex queries

Microtime: '0.90921611785889' sec
Microtime: '0.18274807929993' sec
Microtime: '0.1828088760376' sec
Microtime: '0.18080997467041' sec
Microtime: '0.18127393722534' sec

Describe the solution you'd like
Share session between diferent http request

Describe alternatives you've considered
I have not an alternative, i need do complex queries.

Additional context
Thanks for all

@vzenix vzenix added the enhancement New feature or request label Apr 5, 2023
@transistive
Copy link
Collaborator

Hello @vzenix,

Thank you for raising this request. I don't fully understand this to be honest. The HTTP API is stateless by design.

We are working on an optimization with the bolt protocol, but that is still some months away from releasing. Can you test if your speed improves if you change to the neo4j or bolt scheme in your connection URL?

Kind regards,

Ghlen

@vzenix
Copy link
Author

vzenix commented Apr 19, 2023

I try, but not, it's not a problem of the library itself, the query have a cost of time, but, in the same session neo4j use a cache system for optimize it, and if you don't close the session and you launch again this query the time uses is more less

In other SGBD like mysql/mariadb you have methods for configure persistent session, don't close instantly the session, and then share session betwen separate thread of http requests

I dont know how work bolt, if use a ID of session for example, an static socket for the thread or other method so i don't know if it is possible to do

@stefanak-michal
Copy link
Contributor

@transistive what optimizations on bolt? 😁

@transistive
Copy link
Collaborator

Yes, this is possible, and i was already working on it, but only on bolt. I'll just push my work on it later today. I found it to be exceptionally difficult though, and it requires some smart handling of the server states as you cannot store it with the socket.

@transistive
Copy link
Collaborator

I had a personal use case where opening and closing of the sockets took over 40 percent of the time of each request.

@stefanak-michal
Copy link
Contributor

I don't understand. Persistent connection means that the server (apache) doesn't close TCP connection to database and let it use it by next request handled by php. But how you can affect from php this apache behaviour? Because the php process is not persistent. Even the bolt library is written in php, so how can you keep connection open? What am I missing?

@transistive
Copy link
Collaborator

You can enable a socket to stay alive regardless of a php section: https://www.php.net/manual/en/function.pfsockopen.php

@stefanak-michal
Copy link
Contributor

So you wrote third connection class for Bolt library? ... interesting

@transistive
Copy link
Collaborator

I pushed the work now. It is not even working and I don't have time to write up my analysis but you can check it out if you want:
neo4j-php/Bolt#115

@transistive
Copy link
Collaborator

transistive commented Apr 19, 2023

The key finding for me was that there is not a lot of control given to us by PHP to control the behavior of these sockets. Sometimes they might stay alive, sometimes not. On top of that their ID may or may not be unique, so it is very difficult to provide a second layer to attach the server state to.

@stefanak-michal
Copy link
Contributor

I'll take a look at it later (hopefully this week). I'm really curious. Did you tried to ask me how to deal with this problem in past?

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

No branches or pull requests

3 participants