How To
Stress testing the stability
You think that your distributed system is stable and ready for the production, do not you?
So did I, before trying out this simple “How to break your distributed system” recipe:
- Get fresh dataset for your database (it should have the size comparable to the production data, or even larger)
- Prepare simple command-line agents that emulate user activity (CRUD actions against different entities).
- Take 10-100 of these agents and let them boil in stress mode (1-5 sec. or no delay between actions)
- Fire up all distributed automation/processing services that you have in the picture (obviously, in the stress mode, as well)
- Optional: continuously stir connectivity to the Database and Application Virtual Machines
- Let everything cook for some time
My first unhandled exception (it was a deadlock) bubbled up within 30 seconds after firing this whole thing up. And it is really to reproduce this one - you just have to restart everything and wait for a minute or so.
The system would be called relatively stable if it can survive 24h in the stress mode (and validation proves that all the scheduled tasks have been properly completed).
Linq queries with parameters for your ORM IRepository
Ricardo Cavalcanti has raised question on fluent passing of parameters into the queries encapsulated by the QueryFor (specification) pattern.
Let’s talk about the easiest option of passing parameters, first. It requires no new code at all and is just about chaining queries:
var list = customers .Find<ImportantCustomers>() .Where(c => c.City == "Ufa");
Where comes from the in line extension method provided by Linq.
However, in certain situations Linq might be not enough. This involves queries that encapsulate come complex business logic or require parameter pre-processing, that you want to hide away.
How to peek inside Boo compiler - part 2
Here’s even shorter way of getting to see the Boo compiler in action with details:
- Get yourself latest SharpDevelop (15MB)
- Create new Boo project
- Paste the code below and hit F5. It will print AST in XML to the console
import System
import Boo.Lang.Compiler.IO
import Boo.Lang.Compiler.Pipelines
import Boo.Lang.Compiler
script = """abstract class BaseWorkflow[of X]:
abstract def Process(record as X):
pass
class MyWorkflow(BaseWorkflow[of int]):
def Process(record as int):
print record"""
booC = BooCompiler()
booC.Parameters.Input.Add(StringInput("script", script))
booC.Parameters.Pipeline = ParseAndPrintXml()
booC.Parameters.Ducky = true
context = booC.Run()
if context.GeneratedAssembly is null:
print join(e for e in context.Errors, "\n")
print "Press any key to continue . . . "
Console.ReadKey(true)
It seems trivial so now, but this little snippet could’ve saved me a couple of hours this morning while I’ve been trying to implement custom DSL workflow around a generic base class.
Matrix algorithm for rendering XtraLayout designs into Web UI
In the past post on using XtraLayout component by DevExpress as a simple but powerful run-time designer I’ve mentioned rendering designs into Web UI. Here’s simple recipe for the matrix algorithm that is actually used to render XtraLayout-generated form designs in web UI of xLim 2 implementation.
This implementation does not require creating groups for every logical section like it has been done in XAF Web UI (and defining some custom orientation direction there) - all group contents sit within one table. Additionally this makes the designs reusable for WPF, Windows.Forms and Silverlight UI rendering (xLim 2 compatible renderer prototypes already exist for the first two).
Basically the UI rendering process happens in two steps. First, we check out every single control in the group and register its coordinates. We are only interested in unique X and Y values at this step.
Then, we count number of unique non-zero X values (that’s the number of columns in our table) and number of unique non-zero Y values (that’s the number of rows in our table). After that we calculate the sizes of these columns and rows (derive them from actual X, Y values). Widths will get sizes in percentages, since normally we want our forms to resize with the browser window.
In second pass we simply render all the controls into cells of the HTML table, while assigning appropriate RowSpan and ColSpan to these cells.
Overview of creating custom DSL with Boo
Here’s a short overview of creating custom DSL with Boo. It will serve as technical intro point to the Capture business requirements with Boo-based DSL series.
Basically, when we create custom DSL with Boo, we just add our own steps to the Boo compiler pipeline. These steps inform the compiler how to transform our DSL to valid Boo syntax. Then, the actual compilation steps kick off and compile the results into .NET code.
Since Boo syntax itself is also quite flexible and customizable, later on we can take advantage of this too and make our DSL even more expressive.
One of the transformation approaches (I think Ayende came up with it, although not 100% sure about that) works like this:
Using Windows Server 2008 64 bit as a development workstation
As you may already know, it is a common trend for some developers to use Windows Server 2008 for the development environment. I’ve done the same thing a couple of months ago (picking 64 bit version).
Here are some advantages of this:
- Performance is a bit better than in Vista (and it is more stable as any server has to be)
- It is said that 64 bit support here is better than in the previous OSes (64 bit support allows you to use more than 3GBs of RAM and utilize you Intel Core 2 processors more efficiently)
- Some trojans and viruses will have hard time running under 64 bit.
- It forces you to get familiar with the new technologies and concepts by Microsoft (I did skip Vista)
- It is free for 240 days
Update. Although, Windows Server and Windows Vista share the same codebase, there are yet diffs in the configuration (that’s not just about running services) that give some edge to Server 2008 in the overall performance. Here are some links:
How to implement unit-testable abstraction and reusable domain models with IoC + ORM?
In the previous post in ORM+IoC series we’ve managed to decouple away from the ORM-based collection and the literal-based syntax (which was bound to the logics of eXpress Persistent Objects ORM).
In this post we’ll try to get rid of all the remaining coupling (while making it unit-testable) and even add domain-based extensibility that is easy to implement.
Let’s modify the code:
public sealed class DisableAllAccounts : ICommand
{
private readonly IOrderedQueryable<IAccount> _accounts;
private readonly ILog _log;
public DisableAllAccounts(IOrderedQueryable<IAccount> accounts, ILog log)
{
_accounts = accounts;
_log = log;
}
public void Execute()
{
_log.Write("Disabling accounts:");
var accounts = from c in _accounts
where (c.Disabled == false)
select c;
foreach (var account in accounts)
{
IComment comment = account.CreateComment();
comment.Text = string.Format("Account {0} was disabled on {1}",
account.FirstName, DateTime.Now);
comment.Save();
account.Disabled = true;
account.Save();
}
}
}
Search
Archives
Recent Comments
- aCoder on Extension methods for interfaces
- Requirements for the Photon .NET project | Rinat Abdullin on IRepository, cross-cutting concerns and flexibility
- Nicholas Blumhardt on Extension methods for interfaces
- aCoder on IRepository, cross-cutting concerns and flexibility
- Rinat Abdullin on Blog upgraded
- Rinat Abdullin on Extension methods for interfaces
- IRepository, cross-cutting concerns and flexibility | Rinat Abdullin on Extension methods for interfaces
- Bill Pierce on Blog upgraded
- aCoder on Extension methods for interfaces
