Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Adding a command line parameter "-db-host" to optionally specify a re… #79

Merged
merged 1 commit into from
Apr 10, 2017

Conversation

kevand900
Copy link
Contributor

…mote machine to host the mysql database.

This option is to be used with "--i-am-not-benchmarking".
Changes were made in PerfOptions.php for the command line parsing, and DatabaseInstaller.php for installing the database.
Drupal7, Mediawiki, and Wordpress are the targets which support this feature presently.


--ON THE SERVER RUNNING MYSQL--

Edit my.cnf
$sudo vim /etc/mysql.cnf

Comment out '#skip-networking' if present:
Change to 'bind-address=0.0.0.0'

Restart the server:
$sudo service mariadb stop
$sudo service mariadb start

Create a user 'root' with IP of the machine running OSS:
MariaDB [(none)]>CREATE USER 'root'@'' IDENTIFIED BY 'root';

Grant Privileges to this user:
MariaDB [(none)]>GRANT ALL PRIVILEGES ON . TO 'root'@'' IDENTIFIED BY 'root' WITH GRANT OPTION;
MariaDB [(none)]>FLUSH PRIVILEGES;

Make sure there is a user named 'root'@'localhost.localdomain':
MariaDB [(none)]>SELECT User, Host FROM mysql.user;
+----------+-----------------------+
| User | Host |
+----------+-----------------------+
| root | 127.0.0.1 |
| wp_bench | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | localhost.localdomain |
+----------+-----------------------+

Allow remote access through IPTables:

iptables -P INPUT ACCEPT

iptables -F

iptables -A INPUT -i lo -j ACCEPT


ON MACHINE RUNNING OSS
Test connection from machine running OSS:
$mysql -u root -proot -h


When running OSS, add the command line parameter "db-host=" along with "--i-am-not-benchmarking"


@mofarrell mofarrell self-assigned this Feb 6, 2017
@mxw mxw requested review from mofarrell and mxw February 28, 2017 20:31
Copy link
Contributor

@mofarrell mofarrell left a comment

Choose a reason for hiding this comment

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

First its worth mentioning that this will make the benchmarks inaccurate, and shouldn't be used to measure HHVM performance. The unpredictability of the network accesses, will add variance.

It would be best if this worked for all frameworks. It seems like you only set it up for a couple.

@@ -110,6 +110,8 @@

public bool $notBenchmarking = false;

public ?string $dbHost; //The hostname/IP of server which hosts the database.
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need to be optionally null, and if it is null things will break.


$file = __DIR__.'/temp.php';
$file_contents = file_get_contents($file);
$file_contents = preg_replace('/^.*\'host\' => \'.*$/m', ' \'host\' => \''.$this->options->dbHost.'\',', $file_contents );
Copy link
Contributor

Choose a reason for hiding this comment

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

80 chars per line. This should happen everywhere.

@@ -31,6 +31,15 @@ public function install(): void {
);
}

copy('compress.zlib://' . __DIR__.'/settings.php.gz', __DIR__.'/temp.php');
Copy link
Contributor

Choose a reason for hiding this comment

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

This section is modifying the files that get checked in. We don't want to do that if possible. This should modify the files after they are copied to the tmp directory used for the test.

Also consider putting a pattern in the settings.php file that you match for. Something like:
__DB_HOST__. You can find other parts of this project that use that style.

@@ -46,8 +48,8 @@ public function installDatabase(): bool {
$this->checkMySQLConnectionLimit();
return false;
}

$conn = mysql_connect('127.0.0.1', $db, $db);

Copy link
Contributor

Choose a reason for hiding this comment

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

Try not to add whitespace at the end of lines.

@@ -40,6 +40,11 @@ public function install(): void {
$cache_dir = $this->getSourceRoot().'/mw-cache';
mkdir($cache_dir);

$file = __DIR__.'/LocalSettings.php';
Copy link
Contributor

Choose a reason for hiding this comment

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

Just like with drupal7 this should modify the file after it has been copied to the tmp directory where the test is going to be run from. (And use a pattern)

$file = __DIR__.'/wp-config.php';
$file_contents = file_get_contents($file);
$file_contents = preg_replace('/^.*DB_HOST.*$/m', 'define(\'DB_HOST\', \''.$this->options->dbHost.'\');', $file_contents );
file_put_contents($file, $file_contents);
Copy link
Contributor

Choose a reason for hiding this comment

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

Again try using a pattern, and modify the temp copy not the checked in files.

Copy link
Contributor

@mofarrell mofarrell left a comment

Choose a reason for hiding this comment

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

It would be best if a setting like this worked for all frameworks.

@@ -292,6 +295,10 @@ public function __construct(Vector<string> $argv) {

$argTempDir = $this->getNullableString('temp-dir');

if(array_key_exists('db-host', $o)){
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be an option that requires --i-am-not-benchmarking. Use one of the getNullableString functions to make it so.

@@ -30,11 +30,16 @@ public function install(): void {
$this->getSourceRoot().'/sites/default',
);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid unneeded spaces here as well.

@kevand900 kevand900 force-pushed the remoteDB branch 4 times, most recently from 23ad5fe to 1bc23ee Compare March 22, 2017 23:45
@kevand900
Copy link
Contributor Author

Can you please review? Thanks!

@mofarrell mofarrell merged commit add27b4 into facebookarchive:master Apr 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants