Skip to content

Commit

Permalink
Adding a way to simulate a non trivial work load
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Dec 20, 2012
1 parent cfbf67c commit 5970bc0
Show file tree
Hide file tree
Showing 12 changed files with 601 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Raven.SimulatedWorkLoad/App.config
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="RavenDB" connectionString="Url=http://localhost:8080;Database=Load"/>
</connectionStrings>
<appSettings>
<add key="DataPath" value="C:\Work\Temp"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
21 changes: 21 additions & 0 deletions Raven.SimulatedWorkLoad/Indexes/Users_Locations.cs
@@ -0,0 +1,21 @@
// -----------------------------------------------------------------------
// <copyright file="Users_Locations.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System.Linq;
using Raven.Client.Indexes;
using Raven.SimulatedWorkLoad.Model;

namespace Raven.SimulatedWorkLoad.Indexes
{
public class Users_Locations : AbstractIndexCreationTask<User>
{
public Users_Locations()
{
Map = users =>
from user in users
select new {user.City, user.State, user.StreetAddress, user.Zip};
}
}
}
24 changes: 24 additions & 0 deletions Raven.SimulatedWorkLoad/Indexes/Users_Search.cs
@@ -0,0 +1,24 @@
// -----------------------------------------------------------------------
// <copyright file="Users_Search.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System.Linq;
using Raven.Client.Indexes;
using Raven.SimulatedWorkLoad.Model;

namespace Raven.SimulatedWorkLoad.Indexes
{
public class Users_Search : AbstractIndexCreationTask<User>
{
public Users_Search()
{
Map = users =>
from user in users
select new
{
Query = new object[] { user.First, user.Last, user.Email, user.Email.Split('@'), user.Phone }
};
}
}
}
70 changes: 70 additions & 0 deletions Raven.SimulatedWorkLoad/Indexes/Users_Stats_ByState.cs
@@ -0,0 +1,70 @@
// -----------------------------------------------------------------------
// <copyright file="Users_Stats_ByCountry.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System.Linq;
using Raven.Client.Indexes;
using Raven.SimulatedWorkLoad.Model;

namespace Raven.SimulatedWorkLoad.Indexes
{
public class Users_Stats_ByState : AbstractIndexCreationTask<User, Users_Stats_ByState.Result>
{
public class Result
{
public string State { get; set; }
public int Count { get; set; }
}
public Users_Stats_ByState()
{
Map = users =>
from user in users
select new
{
user.State,
Count = 1
};
Reduce = results =>
from result in results
group result by result.State
into g
select new
{
State = g.Key,
Count = g.Sum(x => x.Count)
};
}
}

public class Users_Stats_ByStateAndcity : AbstractIndexCreationTask<User, Users_Stats_ByStateAndcity.Result>
{
public class Result
{
public string State { get; set; }
public string City { get; set; }
public int Count { get; set; }
}
public Users_Stats_ByStateAndcity()
{
Map = users =>
from user in users
select new
{
user.State,
user.City,
Count = 1
};
Reduce = results =>
from result in results
group result by new { result.State , result.City}
into g
select new
{
g.Key.State,
g.Key.City,
Count = g.Sum(x => x.Count)
};
}
}
}
14 changes: 14 additions & 0 deletions Raven.SimulatedWorkLoad/Model/User.cs
@@ -0,0 +1,14 @@
namespace Raven.SimulatedWorkLoad.Model
{
public class User
{
public string City { get; set; }
public string Email { get; set; }
public string First { get; set; }
public string Last { get; set; }
public string Phone { get; set; }
public string State { get; set; }
public string StreetAddress { get; set; }
public string Zip { get; set; }
}
}
50 changes: 50 additions & 0 deletions Raven.SimulatedWorkLoad/Observing.cs
@@ -0,0 +1,50 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reactive.Disposables;
using Raven.Database.Util;

namespace Raven.SimulatedWorkLoad
{
public class Observing<T> : IObservable<T>
{
private readonly IEnumerator<T> enumerator;
private readonly ConcurrentSet<IObserver<T>> observers = new ConcurrentSet<IObserver<T>>();

public bool Completed { get; private set; }

public Observing(IEnumerable<T> src)
{
enumerator = src.GetEnumerator();
}

public IDisposable Subscribe(IObserver<T> observer)
{
observers.Add(observer);
return Disposable.Create(() => observers.TryRemove(observer));
}

public void Release(int count)
{
if (Completed)
return;

for (int i = 0; i < count; i++)
{
if (enumerator.MoveNext() == false)
{
foreach (var observer in observers)
{
observer.OnCompleted();
}
Completed = true;
break;
}
foreach (var observer in observers)
{
observer.OnNext(enumerator.Current);
}
}
}
}
}

0 comments on commit 5970bc0

Please sign in to comment.