HttpServer.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.BufferPoolMaxMemory = 1000;
  22. serverOptions.BufferPoolSize = 1024 * 10;
  23. if (Program.Debug)
  24. {
  25. serverOptions.BufferSize = 1024 * 16;
  26. }
  27. else
  28. {
  29. serverOptions.BufferSize = 1024 * 8;
  30. }
  31. ApiServer = SocketFactory.CreateTcpServer<HttpHandler>(serverOptions);
  32. ApiServer.Open();
  33. if (!Program.UpDB)
  34. {
  35. RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=1000";
  36. //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";
  37. }
  38. else
  39. {
  40. 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;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=1000";
  41. //RawDb._connectionString = "Server=192.168.2.19;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=64;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
  42. }
  43. ApiServer.Log(LogType.Info, null, $"Debug mode [{Program.Debug}]");
  44. return Task.CompletedTask;
  45. }
  46. public virtual Task StopAsync(CancellationToken cancellationToken)
  47. {
  48. ApiServer.Dispose();
  49. return Task.CompletedTask;
  50. }
  51. }
  52. }