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

Add option to configure MARS on SqlServer Connections #20113

Merged
merged 1 commit into from
Jul 18, 2017
Merged

Add option to configure MARS on SqlServer Connections #20113

merged 1 commit into from
Jul 18, 2017

Conversation

rodrigopedra
Copy link
Contributor

@rodrigopedra rodrigopedra commented Jul 17, 2017

As stated in this docs from Microsoft:

https://github.com/Microsoft/msphpsql/wiki/Recommendations-for-improving-the-performance-of-PDO_SQLSRV-and-SQLSRV#1-multiple-active-result-sets-mars

MARS is enabled by default in both SQLSRV and PDO_SQLSRV drivers. There can be some performance drop when MARS is enabled. Existing code optimized to run in the non-MARS world may show a performance dip when run un-modified with MARS.

This PR adds the ability to disable MARS on a SqlServer connection

As stated in this docs from Microsoft:

https://github.com/Microsoft/msphpsql/wiki/Recommendations-for-improving-the-performance-of-PDO_SQLSRV-and-SQLSRV#1-multiple-active-result-sets-mars

> MARS is enabled by default in both SQLSRV and PDO_SQLSRV drivers. There can be some performance drop when MARS is enabled. Existing code optimized to run in the non-MARS world may show a performance dip when run un-modified with MARS.

This PR adds the ability to configure MARS on a SqlServer connection
@@ -126,6 +126,10 @@ protected function getSqlSrvDsn(array $config)
$arguments['TrustServerCertificate'] = $config['trust_server_certificate'];
}

if (isset($config['multiple_active_resultsets']) && $config['multiple_active_resultsets'] === false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

$arguments['MultipleActiveResultSets'] = $config['multiple_active_resultsets'] ?? true;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, thanks for your observation, Laravel 5.4 still supports PHP 5.6 which does not have the null coalesce operator, so, unfortunately that cannot be used. I hope it gets merged on Laravel 5.4 because that is what I use in production.

Also the argument should only be set to the string value 'false' (not the false boolean value) only when explicitly disabled, because:

  1. MARS is enabled by default (see the Microsoft docs linked above)
  2. The buildConnectString(...) method uses sprintf so a false boolean value would be outputted as the string '0', and if you look in Microsoft documentation linked above the added option to the connectiion string should be MultipleActiveResultSets=false
  3. I used the $config['pooling'] (a few lines above) as an example on how to do it.

@taylorotwell taylorotwell merged commit c27a982 into laravel:5.4 Jul 18, 2017
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.

3 participants