Changeset 4700

Show
Ignore:
Timestamp:
06/12/08 16:45:03 (6 months ago)
Author:
xmlhacker
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/AwsSdbSOAP_Test.csproj

    r4697 r4700  
    5353  </ItemGroup> 
    5454  <ItemGroup> 
     55    <Compile Include="LoadBalancer\WorkerQueue.cs" /> 
    5556    <Compile Include="Program.cs" /> 
    5657    <Compile Include="Properties\AssemblyInfo.cs" /> 
     
    7475  </ItemGroup> 
    7576  <ItemGroup> 
    76     <Content Include="soap.xml"> 
    77       <CopyToOutputDirectory>Always</CopyToOutputDirectory> 
    78     </Content> 
    79   </ItemGroup> 
    80   <ItemGroup> 
    8177    <None Include="App.config" /> 
    8278  </ItemGroup> 
  • trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Program.cs

    r4699 r4700  
    2020        static ExceptionHandlerScope exShield = new ExceptionHandlerScope(); 
    2121        static ProfilerScope profiler = new ProfilerScope(); 
    22         static Scope scope; 
    2322 
    2423        static void Main(string[] args) { 
     
    2726            System.Environment.SetEnvironmentVariable("AWS_PRIVATE_KEY", ConfigurationManager.AppSettings["AWS_PRIVATE_KEY"]); 
    2827 
    29             scope = new Scope(); 
     28            int jobs = (args.Length >= 1) ? int.Parse(args[0]) : int.Parse(ConfigurationManager.AppSettings["DefaultJobs"]); 
     29            int workers = (args.Length >= 2) ? int.Parse(args[1]) : (int.Parse(ConfigurationManager.AppSettings["WorkerQueueMultiplier"]) * Environment.ProcessorCount); 
     30 
     31            int minWorkerThreads = int.Parse(ConfigurationManager.AppSettings["MinimumWorkerThreads"]); 
     32            int minAsyncIOThreads = int.Parse(ConfigurationManager.AppSettings["MinimumAsyncIOThreds"]); 
     33            int maxWorkerThreads = int.Parse(ConfigurationManager.AppSettings["MaximumWorkerThreads"]); 
     34            int maxAsyncIOThreads = int.Parse(ConfigurationManager.AppSettings["MaximumAsyncIOThreads"]); 
     35 
     36            ThreadPool.SetMaxThreads(maxWorkerThreads, maxAsyncIOThreads); 
     37            ThreadPool.SetMinThreads(minWorkerThreads, minAsyncIOThreads); 
     38 
     39            Scope scope = new Scope(); 
    3040            scope += profiler.Scope; 
    3141            scope += logger.Scope; 
    3242            scope += exShield.Scope; 
    3343 
    34             logger.Message = "Processing SOAP requests"; 
     44            Console.WriteLine("Jobs: {0}, Workers: {1}, MinWorkerThreads: {2}, MinAsyncIOThreads: {3}, MaxWorkerThreads: {4}, MaxAsyncIOThreads: {5}", jobs, workers, minWorkerThreads, minAsyncIOThreads, maxWorkerThreads, maxAsyncIOThreads); 
     45             
    3546 
    3647            // Inject code to scope 
     48            //scope.Begin = () => { 
     49            //    PutAttributes().ExecuteAndWait(); 
     50            //}; 
     51 
     52            Stopwatch stopwatch = new Stopwatch(); 
     53 
     54            Console.WriteLine("Current thread id:\t {0}", Thread.CurrentThread.ManagedThreadId); 
     55 
     56            stopwatch.Start(); 
     57            logger.Message = "Processing SOAP requests"; 
    3758            scope.Begin = () => { 
    38                 PutAttributes(scope).ExecuteAndWait(); 
     59                using (WorkerQueue q = new WorkerQueue(workers)) { 
     60                    for (int i = 0; i < jobs; i++) { 
     61                        q.EnqueueTask(PutAttributes()); 
     62                    } 
     63                    Console.WriteLine("{0} jobs have been queued to be processed by {1} worker threads.", jobs, workers); 
     64                } 
    3965            }; 
    4066 
    41             Console.WriteLine("Time ellapsed {0} ms.", profiler.EllapsedTime.TotalMilliseconds);  
     67            stopwatch.Stop(); 
    4268 
    43              
     69            Console.WriteLine("Completed all in:\t {0}ms", stopwatch.ElapsedMilliseconds); 
     70 
    4471 
    4572            //RequestType.Query, "geonames", "100", null, String.Format("['{0}' starts-with '{1}' OR '{0}' = '{1}']", "names", "seattle"))) 
     
    5986        } 
    6087 
    61         static IEnumerable<IAsync> PutAttributes(Scope scope) { 
     88        static IEnumerable<IAsync> PutAttributes() { 
    6289 
    6390            Dictionary<XElement, XElement> responseList = new Dictionary<XElement, XElement>(); 
     
    6693 
    6794            IEnumerable<IAsync>[] requestOperations = new IEnumerable<IAsync>[] { 
    68                 SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoobazzle", "test1", "foo=bar", "bar=baz", "baz=foo"), responseList), 
    69                 SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo555", "test2", "foo=bar", "bar=baz", "baz=foo"), responseList), 
     95                SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo", "test1", "foo=bar", "bar=baz", "baz=foo"), responseList), 
     96                SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo", "test2", "foo=bar", "bar=baz", "baz=foo"), responseList), 
    7097                SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo", "test3", "foo=bar", "bar=baz", "baz=foo"), responseList), 
    7198                SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo", "test4", "foo=bar", "bar=baz", "baz=foo"), responseList), 
     
    80107            stopwatch.Start(); 
    81108 
     109 
     110 
    82111            yield return Async.Parallel(requestOperations); 
    83112 
     
    86115            Console.WriteLine("Completed all in:\t {0}ms", stopwatch.ElapsedMilliseconds); 
    87116            Console.WriteLine("There are a total of {0} result objects in the result dictionary", responseList.Count); 
    88  
    89117            int c = 1; 
    90118            IEnumerator responseEnumerator = responseList.GetEnumerator(); 
    91119 
    92             while (responseEnumerator.MoveNext())
    93                 KeyValuePair<XElement,XElement> responseItem = (KeyValuePair<XElement,XElement>)responseEnumerator.Current; 
     120            while (responseEnumerator.MoveNext())
     121                KeyValuePair<XElement, XElement> responseItem = (KeyValuePair<XElement, XElement>)responseEnumerator.Current; 
    94122                Console.WriteLine(".......................... Begin Message {0} ............................", c); 
    95123                Console.WriteLine("\n"); 
  • trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Scope/LoggerScope.cs

    r4697 r4700  
    55using VVMF.SOA.Common; 
    66 
    7 namespace AwsSdbSOAP_Test { 
    8     public class LoggerScope : HandlerBase { 
     7namespace AwsSdbSOAP_Test 
     8
     9    public class LoggerScope : HandlerBase 
     10    { 
    911        public LoggerScope() : base() { } 
    1012 
    1113        public string Message { get; set; } 
    1214 
    13         protected override void OnEnterScope(EventArgs e) { 
     15        protected override void OnEnterScope(EventArgs e) 
     16        { 
    1417            base.OnEnterScope(e); 
    15             if (!string.IsNullOrEmpty(Message)) { 
     18            if (!string.IsNullOrEmpty(Message)) 
     19            { 
    1620                Console.WriteLine(">LOG --- Entering: {0} ---", Message); 
    1721            } 
    1822        } 
    1923 
    20         protected override void OnLeaveScope(EventArgs e) { 
     24        protected override void OnLeaveScope(EventArgs e) 
     25        { 
    2126            base.OnLeaveScope(e); 
    22             if (!string.IsNullOrEmpty(Message)) { 
     27            if (!string.IsNullOrEmpty(Message)) 
     28            { 
    2329                Console.WriteLine(">LOG --- Leaving: {0} ---", Message); 
    2430                Message = null; 
     
    2632        } 
    2733 
    28         protected override void OnScopeException(ScopeExceptionEventArg e) { 
     34        protected override void OnScopeException(ScopeExceptionEventArg e) 
     35        { 
    2936            base.OnScopeException(e); 
    30             if (!string.IsNullOrEmpty(Message)) { 
     37            if (!string.IsNullOrEmpty(Message)) 
     38            { 
    3139                Console.WriteLine(">LOG --- Exception caught: {0}, Type: {1}  ---", Message, e.Exception.GetType().Name); 
    3240            }