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

Added keep-alive strategy #26

Merged
merged 4 commits into from
May 26, 2022

Conversation

marinhekman
Copy link
Contributor

@marinhekman marinhekman commented May 9, 2022

Added keep-alive strategy as suggested by @mmoreram in #24

  • moved int $connections from Credentials to ConnectionOptions int $numberOfConnections
  • removed array $options from Credentials
  • Added ConnectionOptions, and extended class ConnectionPoolOptions.
  • Using ConnectionPoolOptions in unit tests.
  • SingleConnection add a periodic timer to the loop do a SELECT 1 when ConnectionOptions int $keepAliveIntervalSec has been set
  • On close of destruct the timer, if any, it is removed from the loop

…umberOfConnections

* removed array $options from Credentials
* Added ConnectionOptions, and extended class ConnectionPoolOptions.
* Using ConnectionPoolOptions in unit tests.
* SingleConnection add a periodic timer to the loop do a SELECT 1 when ConnectionOptions int $keepAliveIntervalSec has been set
* On close of destruct the timer, if any, is removed from the loop
…::createConnected to $connection->connect(...)
@marinhekman marinhekman marked this pull request as ready for review May 9, 2022 21:33
@marinhekman
Copy link
Contributor Author

@mmoreram Hi Marc, as you can see I implemented the keep alive strategy. Please review it.

@marinhekman
Copy link
Contributor Author

marinhekman commented May 9, 2022

@mmoreram there is a breaking change. I removed the $connections from Credentials class since the "number of connections" is now in a different class ConnectionPoolOptions which extends the ConnectionOptions class. Seems a more logical place? I also removed the array $options from Credentials since that did not seem to be used, and we have a class ConnectionOptions now? The ConnectionOptions class has a int $keepAliveIntervalSec .

Do you think we need to keep supporting the int $connections in the Credentials class for backwards compatibility? Of course, we can do that if you want.

@marinhekman
Copy link
Contributor Author

marinhekman commented May 12, 2022

Do you think we need to keep supporting the int $connections in the Credentials class for backwards compatibility? Of course, we can do that if you want.

@mmoreram I will look into making it backwards compatible with a deprecations notice.

@marinhekman
Copy link
Contributor Author

@mmoreram ok, it should be backwards compatible now, but review it carefully

Copy link
Member

@mmoreram mmoreram left a comment

Choose a reason for hiding this comment

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

If we can test the feature, that would make sense to be sure that works properly in all drivers. Good implementation, BTW.

$this->keepAliveTimer = Loop::get()->addPeriodicTimer($options->getKeepAliveIntervalSec(), function() {
$qb = $this->createQueryBuilder();
$this->query(
$qb
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure that this format works properly in all adapters? Would make sense to add a ping() method in the interface with all implementations and tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for all current adapters postgresql, sqlite and mysql SELECT 1 is working. I verified mysql in our own implementation, and used online tools for the other 2:
https://extendsclass.com/postgresql-online.html
https://sqliteonline.com/

SELECT 1 is probably the smallest possible SELECT statement there is , so I cannot imagine any sql database not supporting this.

If you still have second thoughts let me know, I will write the ping but it will be equal for all current adapters

[], 10
), $mysqlPlatform);
'test'
), $mysqlPlatform, new ConnectionPoolOptions(10));
Copy link
Member

Choose a reason for hiding this comment

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

Could we test this new feature somehow?

Copy link
Contributor Author

@marinhekman marinhekman May 25, 2022

Choose a reason for hiding this comment

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

we already use the fork in our MSP Challenge project. I will do a re-test and make a quick video capture to share it as "proof" that is works. I can show what happens using Grafana I think.
I think I will be able to show you early next week, so please wait for a while until I get back

Copy link
Member

Choose a reason for hiding this comment

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

Let's be Brave! ;)

@mmoreram mmoreram merged commit 1891dca into driftphp:master May 26, 2022
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.

2 participants