|
9 | 9 | using System.Threading.Tasks; |
10 | 10 | using Microsoft.Extensions.Configuration; |
11 | 11 | using Nacos.V2.DependencyInjection; |
| 12 | +using System.Collections.Generic; |
12 | 13 |
|
13 | 14 | namespace Test.Client |
14 | 15 | { |
@@ -127,6 +128,49 @@ static async Task Main(string[] args) |
127 | 128 | persons = await personService.GetPersons(); |
128 | 129 | Console.WriteLine($"最后获取Persons,persons=[{persons.ToJson()}]"); |
129 | 130 |
|
| 131 | + Stopwatch stopwatch = Stopwatch.StartNew(); |
| 132 | + for (int i = 0; i < 100; i++) |
| 133 | + { |
| 134 | + await personService.GetPersons(); |
| 135 | + } |
| 136 | + stopwatch.Stop(); |
| 137 | + Console.WriteLine($"await:{stopwatch.Elapsed.TotalMilliseconds}"); |
| 138 | + |
| 139 | + stopwatch.Reset(); |
| 140 | + stopwatch.Start(); |
| 141 | + List<Task> tasks = new List<Task>(); |
| 142 | + for (int i = 0; i < 100; i++) |
| 143 | + { |
| 144 | + tasks.Add(personService.GetPersons()); |
| 145 | + } |
| 146 | + await Task.WhenAll(tasks); |
| 147 | + stopwatch.Stop(); |
| 148 | + Console.WriteLine($"tasks await:{stopwatch.Elapsed.TotalMilliseconds}"); |
| 149 | + |
| 150 | + IProductService productService = rpcClient.CreateClient<IProductService>(TestServerName); |
| 151 | + ProductDto product = new ProductDto |
| 152 | + { |
| 153 | + Id = 1000, |
| 154 | + Name="抗原", |
| 155 | + Price = 158.22M |
| 156 | + }; |
| 157 | + int productAddResult = await productService.Add(product); |
| 158 | + Console.WriteLine($"添加Product1:{productAddResult==1}"); |
| 159 | + product = productService.Get(1000); |
| 160 | + Console.WriteLine($"获取添加Product1,id=1000,person=[{product.ToJson()}]"); |
| 161 | + product = new ProductDto |
| 162 | + { |
| 163 | + Id = 2000, |
| 164 | + Name = "N95口罩", |
| 165 | + Price = 35.5M |
| 166 | + }; |
| 167 | + productAddResult = await productService.Add(product); |
| 168 | + Console.WriteLine($"添加Product2:{productAddResult == 1}"); |
| 169 | + product = productService.Get(2000); |
| 170 | + Console.WriteLine($"获取添加Product2,id=2000,person=[{product.ToJson()}]"); |
| 171 | + var products = await productService.GetProducts(); |
| 172 | + Console.WriteLine($"products=[{products.ToJson()}]"); |
| 173 | + |
130 | 174 | //BenchmarkRunner.Run<RpcClientBenchTest>(); |
131 | 175 |
|
132 | 176 | Console.ReadLine(); |
|
0 commit comments