Skip to content

Commit

Permalink
ProductStoreServiceIml:
Browse files Browse the repository at this point in the history
- add more products to stress the client and benchmark / check performances
- fix timer issue
  • Loading branch information
fremag committed Nov 17, 2017
1 parent 874f040 commit 3b20977
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,5 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
/.vscode
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ProductStoreServiceIml : MemoryKeyValueStoreService<string, Product
{
private Random rand = new Random(0);
static ILogger logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.FullName);

Timer timer;
public ProductStoreServiceIml()
{
Insert(new Product { Category = "Fruit", Key = "Orange", Price = 1, Quantity = 5 });
Expand All @@ -24,20 +24,25 @@ public ProductStoreServiceIml()
Insert(new Product { Category = "Vegetable", Key = "Carrots", Price = 1, Quantity = 5 });
Insert(new Product { Category = "Vegetable", Key = "Pumpkin", Price = 1, Quantity = 5 });
Insert(new Product { Category = "Vegetable", Key = "Spinach", Price = 1, Quantity = 5 });
for (int i = 0; i < 5000; i++)
{
Insert(new Product { Category = "Misc", Key = "Vegetable #"+i, Price = 1, Quantity = 5 });
}

Timer timer = new Timer(DoUpdateStore, this, 1000, 2000);
timer = new Timer(DoUpdateStore, this, 1000, 2000);
}

private void DoUpdateStore(object state)
{
var products = GetAllValues();
int idx = rand.Next(products.Count);
var product = products[idx];
foreach (var product in products)
{

product.Price += (1-rand.Next(3)) / 100d;
product.Quantity += rand.Next(2);
// logger.Info($"Update - {product}");
Update(product);
product.Price += (1 - rand.Next(3)) / 100d;
product.Quantity += rand.Next(2);
// logger.Info($"Update - {product}");
Update(product);
}
}
}
}

0 comments on commit 3b20977

Please sign in to comment.