CLR Hosting
We have been running our three C# servers in production for a week now, with no defects and no performance issues. Since we will be expected to process high volumns of messages per second in the next few weeks, we are going to move from the wks GC to the svr GC. wks GC is the default GC used when you run a .NET application in anything other than ASP.NET on a 2+ CPU box - even on a multi CPU machine, and even when using Window services. To load the svr GC, we created a generic Windows service that loads the svr GC, creates an AppDomain, and runs our application: (error checked code not shown) .
CComPtr spRuntimeHost;
HRESULT hr = CorBindToRuntimeEx(NULL, //Retrieve latest version by default
L"svr", //Request a Server (svr) or WorkStation (wks) build of the CLR
STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN,
CLSID_CorRuntimeHost,
IID_ICorRuntimeHost,
(void**)&spRuntimeHost);
//Start the CLR
hr = spRuntimeHost->Start();
//Retrieve the IUnknown default AppDomain
CComPtr pUnk;
hr = spRuntimeHost->GetDefaultDomain(&pUnk);
CComPtr<_AppDomain> spDefAppDomain;
hr = pUnk->QueryInterface(&spDefAppDomain.p);
// Create a domain setup
CComPtr pUnkAppDomainSetup;
hr = spRuntimeHost->CreateDomainSetup(&pUnkAppDomainSetup);
CComPtr pAppDomainSetup;
hr = pUnkAppDomainSetup->QueryInterface(__uuidof(IAppDomainSetup), (void**)&pAppDomainSetup);
// Populate the domain setup
hr = pAppDomainSetup->put_ApplicationBase(_bstr_t(appBase));
hr = pAppDomainSetup->put_ConfigurationFile(_bstr_t(config));
// Create a new domain based on the above setup
CComPtr pNewAppDomain;
LPWSTR pszTest = L"Test";
spRuntimeHost->CreateDomainEx(pszTest, pAppDomainSetup, NULL, &pNewAppDomain);
CComPtr<_AppDomain> spNewAppDomain;
hr = pNewAppDomain->QueryInterface(&spNewAppDomain.p);
CComPtr<_ObjectHandle> objectHandle;
hr = spNewAppDomain->CreateInstance(_bstr_t(assemblyName), _bstr_t(assemblyType), &objectHandle);
/* IAppLoader is from an internal C# assemble generated via tlbexp*/
VARIANT v;
VariantInit(&v);
hr = objectHandle->Unwrap(&v);
_ASSERT(v.pdispVal);
CComPtr pPR;
hr = v.pdispVal->QueryInterface(__uuidof(IAppLoader), (void**) &pPR);
_ASSERT(pPR);
pPR->Run();
Hopefully by the middle of next week we should have a basic comparison of the servers running with wks vs. svr GC.