Browse Source

pre change savechanges to async

Robert 1 year ago
parent
commit
18ddf8efab

+ 18 - 3
Dockerfile

@@ -1,11 +1,26 @@
 #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
 
-FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
+FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base
 RUN sed -i 's/TLSv1.2/TLSv1/g' /etc/ssl/openssl.cnf
 RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
+
+RUN apt-get update \
+    && apt-get install -y --no-install-recommends dialog \
+    && apt-get install -y --no-install-recommends openssh-server \
+	&& mkdir -p /run/sshd \
+    && echo "root:Docker!" | chpasswd 
+	
+COPY sshd_config /etc/ssh/sshd_config
+
+# Install dotnet debug tools
+RUN dotnet tool install --tool-path /tools dotnet-trace \
+ && dotnet tool install --tool-path /tools dotnet-counters \
+ && dotnet tool install --tool-path /tools dotnet-dump \
+ && dotnet tool install --tool-path /tools dotnet-gcdump
+
 EXPOSE 80
 EXPOSE 443
-EXPOSE 54088
+EXPOSE 2222 
 WORKDIR /app
 
 FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
@@ -26,4 +41,4 @@ RUN dotnet publish "EVCB_OCPP.WSServer.csproj" -c Release -o /app/publish /p:Use
 FROM base AS final
 WORKDIR /app
 COPY --from=publish /app/publish .
-ENTRYPOINT ["dotnet", "EVCB_OCPP.WSServer.dll"]
+ENTRYPOINT ["/bin/bash", "-c", "/usr/sbin/sshd && dotnet EVCB_OCPP.WSServer.dll"]

+ 1 - 0
EVCB_OCPP.WSServer/EVCB_OCPP.WSServer.csproj

@@ -60,6 +60,7 @@
     <PackageReference Include="EntityFramework" Version="6.4.4" />
     <PackageReference Include="log4net" Version="2.0.15" />
     <PackageReference Include="System.Threading.Tasks.Dataflow" Version="7.0.0" />
+    <PackageReference Include="Yarp.ReverseProxy" Version="2.0.1" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\SuperWebSocket\SuperWebSocket.csproj" />

+ 4 - 0
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -32,6 +32,7 @@ using Dapper;
 using Microsoft.AspNetCore.Http.HttpResults;
 using MongoDB.Driver.Core.Connections;
 using EVCB_OCPP20.Packet.DataTypes;
+using SuperSocket.SocketBase;
 
 namespace EVCB_OCPP.WSServer.Message;
 
@@ -870,6 +871,9 @@ internal partial class ProfileHandler
 
         if (watch.ElapsedMilliseconds > 5_000)
         {
+            ThreadPool.GetAvailableThreads(out int workerThreads,out int completionThreads);
+            logger.LogInformation($"ThreadPool workerThreads:{workerThreads} completionThreads:{completionThreads}");
+
             await blockingTreePrintService.PrintDbBlockingTree();
             await googleGetTimePrintService.Print();
         }

+ 4 - 2
EVCB_OCPP.WSServer/Program.cs

@@ -40,8 +40,9 @@ namespace EVCB_OCPP.WSServer
             Console.WriteLine("====================================================================================================");
             Console.WriteLine("====================================================================================================");
 
-            //ThreadPool.GetMaxThreads(out var workerThreads, out var completionThreads);
-            //ThreadPool.SetMinThreads((int)(workerThreads * 0.8), (int)(completionThreads * 0.8));
+            ThreadPool.GetMaxThreads(out var workerThreads, out var completionThreads);
+            Console.WriteLine($"Max ThreadPool workerThreads:{workerThreads} completionThreads:{completionThreads}");
+            ThreadPool.SetMinThreads((int)(10), (int)(0));
 
             IHost host = Host.CreateDefaultBuilder(args)
                 //.UseEnvironment("Development")
@@ -56,6 +57,7 @@ namespace EVCB_OCPP.WSServer
                 {
                     //services.AddSingleton<MeterValueGroupSingleHandler>();
                     services.AddProtalServer(hostContext.Configuration);
+
                     services.AddTransient<BlockingTreePrintService>();
                     services.AddTransient<GoogleGetTimePrintService>();
                 })

+ 11 - 1
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -224,6 +224,9 @@ namespace EVCB_OCPP.WSServer
             
             OpenNetwork();
 
+
+            RunHttpConsoleService();
+            return;
             if (!isInDocker)
             {
                 Task consoleReadTask = new Task(RunConsoleInteractive);
@@ -231,7 +234,6 @@ namespace EVCB_OCPP.WSServer
                 //RunConsoleInteractive();
                 return;
             }
-            RunHttpConsoleService();
         }
 
         private void RunConsoleInteractive()
@@ -470,6 +472,14 @@ namespace EVCB_OCPP.WSServer
             app.Urls.Add("http://*:54088");
 
             _ = app.RunAsync();
+
+            var builder = WebApplication.CreateBuilder();
+            builder.Services.AddReverseProxy()
+                .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
+            var yarpApp = builder.Build();
+            yarpApp.Urls.Add("http://*:80");
+            yarpApp.MapReverseProxy();
+            _ = yarpApp.RunAsync();
         }
 
         internal void Stop()

+ 1 - 1
EVCB_OCPP.WSServer/Service/GoogleGetTimePrintService.cs

@@ -25,7 +25,7 @@ namespace EVCB_OCPP.WSServer.Service
             var stopWatch = Stopwatch.StartNew();
             await client.ExecuteAsync(new RestRequest("",method: Method.Get));
             stopWatch.Stop();
-            logger.LogInformation($"Cost {stopWatch.ElapsedMilliseconds}ms");
+            logger.LogInformation($"Google Get Cost {stopWatch.ElapsedMilliseconds}ms");
         }
     }
 }

+ 36 - 1
EVCB_OCPP.WSServer/appsettings.json

@@ -1,5 +1,5 @@
 {
-  "WSPort": 80,
+  "WSPort": 54089,
   "WSSPort": "",
   "LocalAuthAPI": "",
   "LogProvider": "NLog",
@@ -88,6 +88,41 @@
       }
     ]
   },
+  "ReverseProxy": {
+    "Routes": {
+      "routeApi": {
+        "ClusterId": "api",
+        "Match": {
+          "Path": "/api/{**remainder}"
+        },
+        "Transforms": [
+          { "PathRemovePrefix": "/api" }
+        ]
+      },
+      "route1": {
+        "ClusterId": "ocpp",
+        "Match": {
+          "Path": "{**catch-all}"
+        }
+      }
+    },
+    "Clusters": {
+      "ocpp": {
+        "Destinations": {
+          "destination1": {
+            "Address": "http://localhost:54089/"
+          }
+        }
+      },
+      "api": {
+        "Destinations": {
+          "destination1": {
+            "Address": "http://localhost:54088/"
+          }
+        }
+      }
+    }
+  },
   "ConnectionStrings": {
     "ConnectionLogDBContext": "data source=zerova-ev-dev.database.windows.net;initial catalog=StandardOCPP_ConnectionLog;persist security info=True;user id=azdevsoftware;password=1h52dev#az;MultipleActiveResultSets=True;App=EntityFramework;TrustServerCertificate=true;Max Pool Size=200;Connection Lifetime=0;Pooling=true;",
     "MainDBContext": "data source=zerova-ev-dev.database.windows.net;initial catalog=StandardOCPP_Main;;persist security info=True;user id=azdevsoftware;password=1h52dev#az;MultipleActiveResultSets=True;App=EntityFramework;TrustServerCertificate=true;Max Pool Size=1024;Connection Lifetime=0;Pooling=true;Min Pool Size=150;",

+ 12 - 0
sshd_config

@@ -0,0 +1,12 @@
+Port 			2222
+ListenAddress 		0.0.0.0
+LoginGraceTime 		180
+X11Forwarding 		yes
+Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
+MACs hmac-sha1,hmac-sha1-96
+StrictModes 		yes
+SyslogFacility 		DAEMON
+PasswordAuthentication 	yes
+PermitEmptyPasswords 	no
+PermitRootLogin 	yes
+Subsystem sftp internal-sftp