Browse Source

Prototype Microsoft SQL Server database setup

This includes:

* install-client.ps1: a PowerShell script to be run on a Windows Server
  box to download and install SQL Server.
* config/create-sqlserver*.sql: SQL Server T-SQL scripts to create a
  database user and populated database.
* Initial changes to allow sqlserver as a provider for AdoController.cs.

This is somewhat incomplete and needs work:

* How to run the T-SQL scripts if they haven't been pulled down from Git?
* Need wrk or something similar for Windows.
* How to get the python script on the server to run remote commands on the
  client database box?
Malcolm Evershed 12 years ago
parent
commit
1169cd6421

+ 1 - 1
aspnet/src/Application.cs

@@ -41,7 +41,7 @@ namespace Benchmarks.AspNet
                 name: "WithProviders",
                 url: "{controller}/{providerName}/{action}",
                 defaults: new { action = "Index" },
-                constraints: new { controller = "ado|entityframework", providerName = "mysql|postgresql" }
+                constraints: new { controller = "ado|entityframework", providerName = "mysql|postgresql|sqlserver" }
             );
 
             RouteTable.Routes.MapRoute(

+ 3 - 0
aspnet/src/Web.config

@@ -9,6 +9,7 @@
     <add name="MySQL" connectionString="server=localhost; user id=benchmarkdbuser; password=benchmarkdbpass; database=hello_world" providerName="MySql.Data.MySqlClient"/>
     <add name="PostgreSQL" connectionString="server=localhost; user id=benchmarkdbuser; password=benchmarkdbpass; database=hello_world" providerName="Npgsql"/>
     <add name="MongoDB" connectionString="mongodb://localhost"/>
+    <add name="SQLServer" connectionString="server=localhost; user id=benchmarkdbuser; password=B3nchmarkDBPass; database=hello_world" providerName="System.Data.SqlClient"/>
   </connectionStrings>
   <!-- ADO.NET -->
   <system.data>
@@ -16,6 +17,7 @@
       <clear/>
       <add name="MySql.Data.MySqlClient" description="Data Provider for MySQL" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.2.0"/>
       <add name="Npgsql" description="Data Provider for PostgreSQL" invariant="Npgsql" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0"/>
+      <add name="SqlClient Data Provider" description=".Net Framework Data Provider for SqlServer" invariant="System.Data.SqlClient" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
     </DbProviderFactories>
   </system.data>
   <!-- Entity Framework -->
@@ -23,6 +25,7 @@
     <providers>
       <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity, Version=6.7.2.0"/>
       <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql, Version=2.0.12.0"/>
+      <!-- TODO: Need for SQL Server -->
     </providers>
   </entityFramework>
   <system.web>

+ 24 - 0
config/create-sqlserver-login-and-database.sql

@@ -0,0 +1,24 @@
+-- This SQL Server T-SQL script creates the database user and hello_world database.
+--
+-- To run this script, login to an administrator account in Windows, open a command prompt and run:
+--
+-- "%ProgramFiles%\Microsoft SQL Server\110\Tools\binn\sqlcmd.exe" -i <filename of this file>
+--
+
+-- This password has mixed-case and a number to satisfy the Windows password policy
+CREATE LOGIN benchmarkdbuser WITH PASSWORD = 'B3nchmarkDBPass'
+GO
+
+IF EXISTS(SELECT * FROM SYS.DATABASES WHERE NAME='hello_world')
+DROP DATABASE hello_world
+GO
+
+CREATE DATABASE hello_world
+GO
+USE hello_world
+GO
+
+-- Give this user total power over the database
+CREATE USER benchmarkdbuser FOR LOGIN benchmarkdbuser
+EXEC sp_addrolemember 'db_owner', 'benchmarkdbuser'
+GO

+ 51 - 0
config/create-sqlserver.sql

@@ -0,0 +1,51 @@
+-- This SQL Server T-SQL script creates and populates the World and Fortune tables.
+--
+-- To run this script, make sure that you've already run create-sqlserver-login-and-database.sql
+-- to create the database user and database, then open a command prompt and run:
+--
+-- "%ProgramFiles%\Microsoft SQL Server\110\Tools\binn\sqlcmd.exe" -U benchmarkdbuser -P B3nchmarkDBPass -d hello_world -i <filename of this file>
+
+-- TODO: Check for an existing World table and drop it.
+
+CREATE TABLE World (
+  id int NOT NULL IDENTITY PRIMARY KEY,
+  randomNumber int NOT NULL default 0
+)
+GO
+
+-- Populate World table
+DECLARE @RowCount INT
+DECLARE @Random INT
+SET @RowCount = 0
+
+WHILE @RowCount < 10000
+BEGIN
+	SELECT @Random = ((10000 + 1) - 1) * RAND() + 1
+	INSERT INTO World (randomNumber) VALUES (@Random)
+	SET @RowCount = @RowCount + 1
+END
+
+GO
+
+-- TODO: Check for an existing Fortune table and drop it.
+
+-- Note that this uses nvarchar to make sure that the column is Unicode.
+CREATE TABLE Fortune (
+  id int NOT NULL IDENTITY PRIMARY KEY,
+  message nvarchar(2048) NOT NULL
+)
+GO
+
+INSERT INTO Fortune (message) VALUES ('fortune: No such file or directory');
+INSERT INTO Fortune (message) VALUES ('A computer scientist is someone who fixes things that aren''t broken.');
+INSERT INTO Fortune (message) VALUES ('After enough decimal places, nobody gives a damn.');
+INSERT INTO Fortune (message) VALUES ('A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1');
+INSERT INTO Fortune (message) VALUES ('A computer program does what you tell it to do, not what you want it to do.');
+INSERT INTO Fortune (message) VALUES ('Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen');
+INSERT INTO Fortune (message) VALUES ('Any program that runs right is obsolete.');
+INSERT INTO Fortune (message) VALUES ('A list is only as strong as its weakest link. — Donald Knuth');
+INSERT INTO Fortune (message) VALUES ('Feature: A bug with seniority.');
+INSERT INTO Fortune (message) VALUES ('Computers make very fast, very accurate mistakes.');
+INSERT INTO Fortune (message) VALUES ('<script>alert("This should not be displayed in a browser alert box.");</script>');
+INSERT INTO Fortune (message) VALUES ('フレームワークのベンチマーク');
+GO

+ 37 - 0
install-client.ps1

@@ -0,0 +1,37 @@
+# This script downloads and installs SQL Server and opens it on port 1433.
+#
+# To run this script, run an elevated Command Prompt and enter:
+#
+# powershell -ExecutionPolicy Bypass -File <this script's filename>
+
+$basedir = "C:\FrameworkBenchmarks"
+$workdir = "$basedir\installs"
+New-Item -Path $workdir -Type directory -Force | Out-Null
+
+Write-Host "Downloading SQL Server (several GBs)...`n"
+
+# URLs from http://www.microsoft.com/en-us/download/details.aspx?id=35575
+
+$sqlserver_exe_url = "http://download.microsoft.com/download/3/B/D/3BD9DD65-D3E3-43C3-BB50-0ED850A82AD5/SQLServer2012SP1-FullSlipstream-x64-ENU.exe"
+$sqlserver_exe_local = "$workdir\SQLServer2012SP1-FullSlipstream-x64-ENU.exe"
+(New-Object System.Net.WebClient).DownloadFile($sqlserver_exe_url, $sqlserver_exe_local)
+
+$sqlserver_box_url = "http://download.microsoft.com/download/3/B/D/3BD9DD65-D3E3-43C3-BB50-0ED850A82AD5/SQLServer2012SP1-FullSlipstream-x64-ENU.box"
+$sqlserver_box_local = "$workdir\SQLServer2012SP1-FullSlipstream-x64-ENU.box"
+(New-Object System.Net.WebClient).DownloadFile($sqlserver_box_url, $sqlserver_box_local)
+
+Write-Host "Installing SQL Server...`n"
+
+# Install only the SQL Server database engine.
+# Use a default instance name.
+# Make %COMPUTERNAME%\Administrators have administrative rights.
+# Allow Windows Authentication or old-style SQL authentication.
+# The password of the sa account is specified.
+# SQL Server will be listening on TCP port 1433.
+#
+Start-Process "$sqlserver_exe_local" "/q /action=install /features=SQLEngine /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=Administrators /securitymode=SQL /sapwd=S3cr3tS3cr3t /TCPENABLED=1 /IACCEPTSQLSERVERLICENSETERMS" -Wait
+
+Write-Host "Configuring firewall...`n"
+New-NetFirewallRule -DisplayName "SQL 1433" -Action Allow -Direction Inbound -LocalPort 1433 -Protocol TCP | Out-Null
+
+# TODO: Run T-SQL files to create database and tables? To do that, we'd need to have the files config\create-sqlserver*.sql locally