The Digital Nervous System: Scaling with DCOM and C++
Corporate IT is at a crossroads in 1999. Your Active Server Pages (ASP) are likely becoming a nightmare of unmanaged script code. This is what Bill Gates calls the 'Digital Nervous System'-your infrastructure must be responsive, and you cannot achieve that with interpreted VBScript handling your core business logic.
The professional solution is to leverage COM (Component Object Model) for your business tier. We build compiled, thread-safe C++ components using the Active Template Library (ATL) and distribute them across our network using DCOM (Distributed COM). This separates your IIS web server (the presentation tier) from your heavy processing logic (the application tier).
The ATL Middle-Tier Component
Using ATL allows us to build lean COM objects without the overhead of MFC. We focus on STDMETHOD implementations that can be called by any automation-compatible language, including VBScript in ASP.
// ATL implementation for our Business Logic component
STDMETHODIMP CAccountBalance::GetCalculatedInterest(double principal, double* result)
{
if (result == NULL) return E_POINTER;
// Highly optimized business calculations in C++
double rate = 0.0525; // Standard 1999 corporate rate
*result = principal * rate;
return S_OK;
}
Distributing Logic across NT Servers
The power of DCOM lies in its transparency. By using the dcomcnfg utility, you can configure your web server to instantiate these objects on a completely different machine in the server room. This is horizontal scaling before we even had a word for it.
From your ASP script, the call looks identical:
<%
' The beauty of DCOM transparency
Dim objBalance
' This could be running on a 4-way Xeon server in the back room
Set objBalance = Server.CreateObject("BankCorp.AccountBalance")
Dim interest
interest = objBalance.GetCalculatedInterest(10000.00)
Response.Write "Current Accrued Interest: " & interest
Set objBalance = Nothing
%>
The Marshalling Bottleneck
When you move to DCOM, you are now traversing the network. Each call to an interface method incurs the cost of RPC (Remote Procedure Call) and data marshalling. Avoid "chatty" interfaces. Instead of calling SetFirstName(), SetLastName(), and Save(), design a "chunky" interface with a single SaveUser(firstName, lastName) method.
For high-load systems, you MUST wrap these components in MTS (Microsoft Transaction Server). MTS manages thread pooling and object activation/deactivation (JIT activation), which is critical because Windows NT has a relatively high overhead for object creation.
Ensure your components use the "Both" threading model to avoid the Single-Threaded Apartment (STA) bottleneck. If you aren't careful with your marshaling, your multi-threaded IIS server will serialize all calls to your component, killing your scalability. Use CoCreateFreeThreadedMarshaler in your FinalConstruct to let your object be called efficiently from any thread.
Aunimeda designs and builds scalable software architectures - from system design to implementation and ongoing engineering.
Contact us to discuss architecture for your project. See also: Custom Software Development, Web Development