Startup.cs 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using AipDatabase.API.Infrastructures;
  2. using AipGateway.API.Application.Configurations;
  3. using AipGateway.API.Domain.Entities;
  4. using AipGateway.API.Utils;
  5. using Microsoft.Data.SqlClient;
  6. using Serilog;
  7. using System.Data;
  8. using Dapper;
  9. using System.Diagnostics;
  10. using log4net;
  11. using AipGateway.AIP;
  12. using Microsoft.Identity.Client;
  13. using System.Net;
  14. namespace AipGateway.API
  15. {
  16. public class Startup
  17. {
  18. public static void SetSystemConfig()
  19. {
  20. ThreadPool.GetAvailableThreads(out int workerThreads1, out int completionPortThreads1);
  21. ThreadPool.GetMaxThreads(out int workerThreads2, out int completionPortThreads2);
  22. ThreadPool.GetMinThreads(out int workerThreads3, out int completionPortThreads3);
  23. Log.Information(" AvailableThreads: worker({0}), port({1})", workerThreads1, completionPortThreads1);
  24. Log.Information(" MaxThreads: worker({0}), port({1})", workerThreads2, completionPortThreads2);
  25. Log.Information(" MinThreads: worker({0}), port({1})", workerThreads3, completionPortThreads3);
  26. Log.Information(" UseNagleAlgorithm: {0}", System.Net.ServicePointManager.UseNagleAlgorithm);
  27. System.Net.ServicePointManager.UseNagleAlgorithm = false;
  28. Log.Information(" UseNagleAlgorithm: {0}, Application Set.", System.Net.ServicePointManager.UseNagleAlgorithm);
  29. Log.Information(" Expect100Continue: {0}", System.Net.ServicePointManager.Expect100Continue);
  30. System.Net.ServicePointManager.Expect100Continue = false;
  31. Log.Information(" Expect100Continue: {0}, Application Set.", System.Net.ServicePointManager.Expect100Continue);
  32. Log.Information(" CheckCertificateRevocationList: {0}", System.Net.ServicePointManager.CheckCertificateRevocationList);
  33. System.Net.ServicePointManager.CheckCertificateRevocationList = true;
  34. Log.Information(" CheckCertificateRevocationList: {0}, Application Set.", System.Net.ServicePointManager.CheckCertificateRevocationList);
  35. Log.Information("DefaultPersistentConnectionLimit: {0}", System.Net.ServicePointManager.DefaultPersistentConnectionLimit);
  36. Log.Information(" DefaultConnectionLimit: {0}", System.Net.ServicePointManager.DefaultConnectionLimit);
  37. System.Net.ServicePointManager.DefaultConnectionLimit = 2048;
  38. Log.Information(" DefaultConnectionLimit: {0}, Application Set.", System.Net.ServicePointManager.DefaultConnectionLimit);
  39. // Bump up the min threads reserved for this app to ramp connections faster - minWorkerThreads defaults to 4, minIOCP defaults to 4
  40. ThreadPool.SetMinThreads(100, 100);
  41. // Change max connections from .NET to a remote service default: 2
  42. //System.Net.ServicePointManager.DefaultConnectionLimit = 65000;
  43. // Turn off the Expect 100 to continue message - 'true' will cause the caller to wait until it round-trip confirms a connection to the server
  44. //System.Net.ServicePointManager.Expect100Continue = false;
  45. // Can decrease overall transmission overhead but can cause delay in data packet arrival
  46. //System.Net.ServicePointManager.UseNagleAlgorithm = false;
  47. }
  48. public static bool AipFileInitialize(AipFileManager aipFileManager)
  49. {
  50. if (!aipFileManager.Initialize())
  51. {
  52. Log.Error("AipFileInitialize, aipFileManager.Initialize Failed, {0}, {1}", aipFileManager.LastErrNo, aipFileManager.LastErrMsg);
  53. return false;
  54. }
  55. if (!aipFileManager.CreateProfile())
  56. {
  57. Log.Error("AipFileInitialize, aipFileManager.CreateProfile Failed, {0}, {1}", aipFileManager.LastErrNo, aipFileManager.LastErrMsg);
  58. return false;
  59. }
  60. if (!aipFileManager.CreateEngine())
  61. {
  62. Log.Error("AipFileInitialize, aipFileManager.CreateEngine Failed, {0}, {1}", aipFileManager.LastErrNo, aipFileManager.LastErrMsg);
  63. return false;
  64. }
  65. return true;
  66. }
  67. }
  68. }