Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Implemented the drop database command and started writing the C# vers…
…ion of the 10gen driver benchmark.
  • Loading branch information
Samuel Corder authored and Samuel Corder committed Dec 16, 2009
1 parent 1fdaeb6 commit 8d8d147
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -25,3 +25,5 @@ MongoDB.Linq/obj/*
MongoDB.Linq.Tests/bin/*
MongoDB.Linq.Tests/obj/*
MongoDB.Linq.Tests/test-results/*

MongoDB.Driver.Benchmark/bin/*
26 changes: 26 additions & 0 deletions MongoDB.Driver.Benchmark/AssemblyInfo.cs
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("MongoDB.Driver.Benchmark")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
105 changes: 105 additions & 0 deletions MongoDB.Driver.Benchmark/Main.cs
@@ -0,0 +1,105 @@
using System;

namespace MongoDB.Driver.Benchmark
{
/// <summary>
/// This is the standard 10gen benchmark program.
/// </summary>
class MainClass
{
static Document small = new Document();
static Document medium = new Document();
static Document large = new Document();

static int trials = 2;
static int perTrial = 5000;
static int batchSize = 100;

static void SetupDocuments(){
medium.Append("integer", (int) 5);
medium.Append("number", 5.05);
medium.Append("boolean", false);
medium.Append("array", new String[]{"test","benchmark"});

large.Append("base_url", "http://www.example.com/test-me");
large.Append("total_word_count", (int)6743);
large.Append("access_time", DateTime.UtcNow);
large.Append("meta_tags", new Document()
.Append("description", "i am a long description string")
.Append("author", "Holly Man")
.Append("dynamically_created_meta_tag", "who know\n what"));
large.Append("page_structure", new Document().Append("counted_tags", 3450)
.Append("no_of_js_attached", (int)10)
.Append("no_of_images", (int)6));
string[] words = new string[]{"10gen","web","open","source","application","paas",
"platform-as-a-service","technology","helps",
"developers","focus","building","mongodb","mongo"};
string[] harvestedWords = new string[words.Length * 20];
for(int i = 0; i < words.Length * 20; i++){
harvestedWords[i] = words[i % words.Length];
}
large.Append("harvested_words", harvestedWords);
}

static void SetupInsert(Database db, string col){
try{
db.MetaData.DropCollection(col);
}catch(MongoCommandException mce){
//swallow for now.
}
}

static void TestInsert(string name, Database db, string col, Document doc){
TimeSpan ret = TimeSpan.MaxValue;
for(int i = 0; i < trials; i++){
DateTime start = DateTime.Now;
Insert(db,col,doc);
DateTime stop = DateTime.Now;
TimeSpan t = stop - start;
if(t < ret){
ret = t;
}
}

int opsSec = (int)(perTrial/ret.TotalSeconds);
Console.Out.WriteLine(String.Format("{0}{1} {2}", name + new string('.', 60 - name.Length), opsSec, ret));
}

static void Insert(Database db, string col, Document doc){
for(int i = 0; i < perTrial; i++){
Document ins = new Document();
doc.CopyTo(ins);
ins.Append("x", i);
db[col].Insert(ins);
}
}
static void runInsertTest(string name, Database db, string col, Document doc, bool index){
SetupInsert(db,"col");
if(index){
Document idx = new Document().Append("x", IndexOrder.Ascending);
db[name].MetaData.CreateIndex(idx,false);
}
TestInsert(name, db, col,doc);
}

public static void Main (string[] args)
{
SetupDocuments();

Mongo m = new Mongo();
m.Connect();
Database db = m["benchmark"];
db.MetaData.DropDatabase();

runInsertTest("insert (small, no index)", db, "small_none",small,false);
runInsertTest("insert (medium, no index)", db, "medium_none",medium,false);
runInsertTest("insert (large, no index)", db, "large_none",large,false);

runInsertTest("insert (small, indexed)", db, "small_index",small,true);
runInsertTest("insert (medium, indexed)", db, "medium_index",medium,true);
runInsertTest("insert (large, indexed)", db, "large_index",large,true);


}
}
}
1 change: 1 addition & 0 deletions MongoDB.Driver.Benchmark/MongoDB.Driver.Benchmark.csproj
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>9.0.21022</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>MongoDB.Driver.Benchmark</RootNamespace> <AssemblyName>MongoDB.Driver.Benchmark</AssemblyName> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug</OutputPath> <DefineConstants>DEBUG</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>none</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Release</OutputPath> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="System" /> </ItemGroup> <ItemGroup> <Compile Include="Main.cs" /> <Compile Include="AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\MongoDBDriver\MongoDB.Driver.csproj"> <Project>{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}</Project> <Name>MongoDB.Driver</Name> </ProjectReference> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /></Project>
Expand Down
12 changes: 6 additions & 6 deletions MongoDB.Linq.Tests/MongoDB.Linq.Tests.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -31,16 +31,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\redist\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\redist\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
Expand Down Expand Up @@ -74,7 +74,7 @@
<Name>MongoDB.Driver</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
6 changes: 3 additions & 3 deletions MongoDB.Linq/MongoDB.Linq.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -61,7 +61,7 @@
<Name>MongoDB.Driver</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
45 changes: 23 additions & 22 deletions MongoDBDriver.sln
Expand Up @@ -3,52 +3,53 @@ Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver", "MongoDBDriver\MongoDB.Driver.csproj", "{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}"
EndProject
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "Packages", "Packages.mdproj", "{502F3381-58AA-461B-B9D8-12578A588C61}"
Project("{9344bdbb-3e7f-41fc-a0dd-8665d75ee146}") = "Packages", "Packages.mdproj", "{502F3381-58AA-461B-B9D8-12578A588C61}"
EndProject
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "MongoDBDriverTranslation", "MongoDBDriverTranslation\MongoDBDriverTranslation.mdproj", "{DCBE47DD-59A6-4212-AA4A-142838088B69}"
Project("{9344bdbb-3e7f-41fc-a0dd-8665d75ee146}") = "MongoDBDriverTranslation", "MongoDBDriverTranslation\MongoDBDriverTranslation.mdproj", "{89828A32-BE79-4B3A-8605-0B32C06F942F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver.Tests", "MongoDB.Net-Tests\MongoDB.Driver.Tests.csproj", "{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Linq", "MongoDB.Linq\MongoDB.Linq.csproj", "{2E48891E-72F9-445D-9A5A-DBA787BFFE9E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Linq.Tests", "MongoDB.Linq.Tests\MongoDB.Linq.Tests.csproj", "{870FE8E1-3461-4C79-BF25-9C35E41BF582}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver.Benchmark", "MongoDB.Driver.Benchmark\MongoDB.Driver.Benchmark.csproj", "{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}.Release|Any CPU.Build.0 = Release|Any CPU
{502F3381-58AA-461B-B9D8-12578A588C61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{502F3381-58AA-461B-B9D8-12578A588C61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{502F3381-58AA-461B-B9D8-12578A588C61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{502F3381-58AA-461B-B9D8-12578A588C61}.Release|Any CPU.Build.0 = Release|Any CPU
{DCBE47DD-59A6-4212-AA4A-142838088B69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCBE47DD-59A6-4212-AA4A-142838088B69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCBE47DD-59A6-4212-AA4A-142838088B69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCBE47DD-59A6-4212-AA4A-142838088B69}.Release|Any CPU.Build.0 = Release|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Release|Any CPU.Build.0 = Release|Any CPU
{2E48891E-72F9-445D-9A5A-DBA787BFFE9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E48891E-72F9-445D-9A5A-DBA787BFFE9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E48891E-72F9-445D-9A5A-DBA787BFFE9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E48891E-72F9-445D-9A5A-DBA787BFFE9E}.Release|Any CPU.Build.0 = Release|Any CPU
{502F3381-58AA-461B-B9D8-12578A588C61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{502F3381-58AA-461B-B9D8-12578A588C61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Release|Any CPU.Build.0 = Release|Any CPU
{870FE8E1-3461-4C79-BF25-9C35E41BF582}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{870FE8E1-3461-4C79-BF25-9C35E41BF582}.Debug|Any CPU.Build.0 = Debug|Any CPU
{870FE8E1-3461-4C79-BF25-9C35E41BF582}.Release|Any CPU.ActiveCfg = Release|Any CPU
{870FE8E1-3461-4C79-BF25-9C35E41BF582}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
{89828A32-BE79-4B3A-8605-0B32C06F942F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89828A32-BE79-4B3A-8605-0B32C06F942F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}.Release|Any CPU.Build.0 = Release|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 0.1
StartupItem = MongoDBDriver\MongoDB.Driver.csproj
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion MongoDBDriver/DatabaseMetaData.cs
Expand Up @@ -40,7 +40,8 @@ public class DatabaseMetaData
}

public Boolean DropDatabase(){
throw new NotImplementedException();
Document result = db.SendCommand("dropDatabase");
return result.Contains("ok") && ((double)result["ok"] == 1);
}

public void AddUser(string username, string password){
Expand Down
3 changes: 2 additions & 1 deletion MongoDBDriver/MongoDB.Driver.csproj
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -34,6 +34,7 @@
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<RootNamespace>MongoDB.Driver</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
2 changes: 1 addition & 1 deletion Packages.mdproj
Expand Up @@ -8,7 +8,7 @@
<Packages>
<Packages>
<Package name="Tarball">
<Builder TargetDirectory="/home/dev/Projects/MongoDBDriver/MongoDBDriver" DefaultConfiguration="Debug" ctype="TarballDeployTarget">
<Builder TargetDirectory="..\..\..\..\..\home\dev\Projects\MongoDBDriver\MongoDBDriver" DefaultConfiguration="Debug" ctype="TarballDeployTarget">
<ChildEntries>
<SolutionItemReference path="MongoDBDriver\MongoDBDriver.csproj" />
</ChildEntries>
Expand Down

0 comments on commit 8d8d147

Please sign in to comment.