HttpServer.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 * 10;
  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=4;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=1000";
  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=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";
  34. //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";
  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. }