Changeset 4700
- Timestamp:
- 06/12/08 16:45:03 (6 months ago)
- Files:
-
- trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/AwsSdbSOAP_Test.csproj (modified) (2 diffs)
- trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/LoadBalancer (added)
- trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/LoadBalancer/WorkerQueue.cs (added)
- trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Program.cs (modified) (6 diffs)
- trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Scope/LoggerScope.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/AwsSdbSOAP_Test.csproj
r4697 r4700 53 53 </ItemGroup> 54 54 <ItemGroup> 55 <Compile Include="LoadBalancer\WorkerQueue.cs" /> 55 56 <Compile Include="Program.cs" /> 56 57 <Compile Include="Properties\AssemblyInfo.cs" /> … … 74 75 </ItemGroup> 75 76 <ItemGroup> 76 <Content Include="soap.xml">77 <CopyToOutputDirectory>Always</CopyToOutputDirectory>78 </Content>79 </ItemGroup>80 <ItemGroup>81 77 <None Include="App.config" /> 82 78 </ItemGroup> trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Program.cs
r4699 r4700 20 20 static ExceptionHandlerScope exShield = new ExceptionHandlerScope(); 21 21 static ProfilerScope profiler = new ProfilerScope(); 22 static Scope scope;23 22 24 23 static void Main(string[] args) { … … 27 26 System.Environment.SetEnvironmentVariable("AWS_PRIVATE_KEY", ConfigurationManager.AppSettings["AWS_PRIVATE_KEY"]); 28 27 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(); 30 40 scope += profiler.Scope; 31 41 scope += logger.Scope; 32 42 scope += exShield.Scope; 33 43 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 35 46 36 47 // 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"; 37 58 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 } 39 65 }; 40 66 41 Console.WriteLine("Time ellapsed {0} ms.", profiler.EllapsedTime.TotalMilliseconds);67 stopwatch.Stop(); 42 68 43 69 Console.WriteLine("Completed all in:\t {0}ms", stopwatch.ElapsedMilliseconds); 70 44 71 45 72 //RequestType.Query, "geonames", "100", null, String.Format("['{0}' starts-with '{1}' OR '{0}' = '{1}']", "names", "seattle"))) … … 59 86 } 60 87 61 static IEnumerable<IAsync> PutAttributes( Scope scope) {88 static IEnumerable<IAsync> PutAttributes() { 62 89 63 90 Dictionary<XElement, XElement> responseList = new Dictionary<XElement, XElement>(); … … 66 93 67 94 IEnumerable<IAsync>[] requestOperations = new IEnumerable<IAsync>[] { 68 SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo bazzle", "test1", "foo=bar", "bar=baz", "baz=foo"), responseList),69 SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo 555", "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), 70 97 SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo", "test3", "foo=bar", "bar=baz", "baz=foo"), responseList), 71 98 SimpleDBService.MakeSoapRequestAsync<XElement>(RequestType.PutAttributes, service.GetMessage(RequestType.PutAttributes, "testfoo", "test4", "foo=bar", "bar=baz", "baz=foo"), responseList), … … 80 107 stopwatch.Start(); 81 108 109 110 82 111 yield return Async.Parallel(requestOperations); 83 112 … … 86 115 Console.WriteLine("Completed all in:\t {0}ms", stopwatch.ElapsedMilliseconds); 87 116 Console.WriteLine("There are a total of {0} result objects in the result dictionary", responseList.Count); 88 89 117 int c = 1; 90 118 IEnumerator responseEnumerator = responseList.GetEnumerator(); 91 119 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; 94 122 Console.WriteLine(".......................... Begin Message {0} ............................", c); 95 123 Console.WriteLine("\n"); trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Scope/LoggerScope.cs
r4697 r4700 5 5 using VVMF.SOA.Common; 6 6 7 namespace AwsSdbSOAP_Test { 8 public class LoggerScope : HandlerBase { 7 namespace AwsSdbSOAP_Test 8 { 9 public class LoggerScope : HandlerBase 10 { 9 11 public LoggerScope() : base() { } 10 12 11 13 public string Message { get; set; } 12 14 13 protected override void OnEnterScope(EventArgs e) { 15 protected override void OnEnterScope(EventArgs e) 16 { 14 17 base.OnEnterScope(e); 15 if (!string.IsNullOrEmpty(Message)) { 18 if (!string.IsNullOrEmpty(Message)) 19 { 16 20 Console.WriteLine(">LOG --- Entering: {0} ---", Message); 17 21 } 18 22 } 19 23 20 protected override void OnLeaveScope(EventArgs e) { 24 protected override void OnLeaveScope(EventArgs e) 25 { 21 26 base.OnLeaveScope(e); 22 if (!string.IsNullOrEmpty(Message)) { 27 if (!string.IsNullOrEmpty(Message)) 28 { 23 29 Console.WriteLine(">LOG --- Leaving: {0} ---", Message); 24 30 Message = null; … … 26 32 } 27 33 28 protected override void OnScopeException(ScopeExceptionEventArg e) { 34 protected override void OnScopeException(ScopeExceptionEventArg e) 35 { 29 36 base.OnScopeException(e); 30 if (!string.IsNullOrEmpty(Message)) { 37 if (!string.IsNullOrEmpty(Message)) 38 { 31 39 Console.WriteLine(">LOG --- Exception caught: {0}, Type: {1} ---", Message, e.Exception.GetType().Name); 32 40 }
