HttpServer.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using BeetleX;
  2. using BeetleX.EventArgs;
  3. using Microsoft.Extensions.Hosting;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. namespace PlatformBenchmarks
  10. {
  11. public class HttpServer : IHostedService
  12. {
  13. public static IServer ApiServer;
  14. public virtual Task StartAsync(CancellationToken cancellationToken)
  15. {
  16. ArraySegment<byte> date = GMTDate.Default.DATE;
  17. ServerOptions serverOptions = new ServerOptions();
  18. serverOptions.LogLevel = LogType.Error;
  19. serverOptions.DefaultListen.Port = 8080;
  20. serverOptions.Statistical = false;
  21. serverOptions.BufferSize = 1024 * 8;
  22. serverOptions.BufferPoolMaxMemory = 1000;
  23. serverOptions.BufferPoolSize = 1024 * 8;
  24. ApiServer = SocketFactory.CreateTcpServer<HttpHandler>(serverOptions);
  25. ApiServer.Open();
  26. if (!Program.UpDB)
  27. {
  28. RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
  29. // RawDb._connectionString = "Server=192.168.2.19;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
  30. }
  31. else
  32. {
  33. // RawDb._connectionString = "Server=192.168.2.19;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=32;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
  34. RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=64;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
  35. }
  36. ApiServer.Log(LogType.Info, null, $"Debug mode [{Program.Debug}]");
  37. return Task.CompletedTask;
  38. }
  39. public virtual Task StopAsync(CancellationToken cancellationToken)
  40. {
  41. ApiServer.Dispose();
  42. return Task.CompletedTask;
  43. }
  44. }
  45. }