我有一个 Blazor 服务器端应用程序,它使用不使用实体框架的 CosmosDB 自定义身份提供程序。我想将应用程序转换为托管在 Asp.net Core 上的 Blazor WebAssembly。
我的 Blazor 服务器端 Startup.cs 自定义提供程序如下所示:
services.AddTransient<IRoleStore<ApplicationRole>, CosmosDBRoleStore<ApplicationRole>>();
services.AddTransient<IUserStore<ApplicationUser>, CosmosDBUserStore<ApplicationUser>>();
services.AddIdentity<ApplicationUser, ApplicationRole>().AddDefaultTokenProviders();
services.AddAuthentication();
services.AddAuthorization();
Run Code Online (Sandbox Code Playgroud)
Asp.net Core 上托管的Visual Studio for Blazor WebAssembly 中的当前模板使用 Asp.Net Core Identity + SQL Server 之上的 Identity Server4,并且需要来自 Entity Framework Core 的 DBContext。
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<ApplicationUser>(options =>
options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddIdentityServer().AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication().AddIdentityServerJwt();
Run Code Online (Sandbox Code Playgroud)
我安装了自定义 Cosmos DB 身份提供程序,但是该行
services.AddIdentityServer().AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
Run Code Online (Sandbox Code Playgroud)
需要实体框架 DBContext 来填充 IdentityServer4 的所有参数。
我分析了四种情况:
1)在我的自定义身份提供程序之上使用实体框架,但它几乎需要完全重新编码,因为它使用深度自定义的 CosmosDB 与自定义登录/注销/注册等页面的集成。
2)在我的自定义提供程序之上使用 Identity Server4,但我对它很陌生,整个框架很复杂,所有使用 Asp.Net …
我使用Asp.net Web Api 2构建了一组3个API,使用Azure云服务工作者角色中的OWIN自托管.工作者角色通过自定义域公开到Internet.
每个API都有一个控制器,执行一些正常的字典操作,表调用和Azure Redis调用.2个请求只需执行一次Redis呼叫,并在大约10ms内返回.通过所有API代码时的平均调用是150ms.答案是一个大小约为10k的JSON对象.
一切正常,但我有问题.
我在周围每秒25峰连接和每天不超过2万个请求,我勉强可以得到下面的CPU 40%与3天青D2_V2(2个芯,8GB RAM)情况下运行.我遇到了麻烦,因为我每个月花费近1.5k美元用于每秒15-25次呼叫的Api.如果我删除或缩小实例,CPU上升到55-60%, Redis和Azure表调用减慢很多,API请求需要3-5秒才能恢复.
我尽我所能尝试了一切,我认为可能是一些机器人或DDos攻击,所以我安装了nuget包WebApi Throttle,每个IP每秒最多设置1个请求.没有改变.
我查看了所有代码配置,以削减未经优化的部分,但1次调用只是调用redis并返回,其他非常干净和简单C#返回150ms,有2个azure表调用+ 1个azure队列集.
该API控制器是异步,一切都是异步.
我启用了Profiling,CPU在主要的azure进程中很高,而Redis Get方法,这里没有任何其他相关内容,没有瓶颈.我启用了诊断,没有错误.
我安装了Application Insights,在这里我看到一些奇怪的东西无法判断它是否正常.
我看到这个IP:13.88.23.0使用通常在正常请求中使用的查询字符串值向API 发出数千个请求.其中很多都失败了.这个IP本身就是Azure,为什么要调用Api?其中一些请求停留了几分钟,我可以从Application insights面板看到,它始终是相同的IP.
然后我看到剩下的日志,依赖项等,没有任何相关性.
除此之外,我该怎么做才能理解这个问题? 我不能认为每天只有200万次呼叫消耗如此多的CPU资源是否正常?
我可以使用其他分析技术吗?
根据您的经验,在正常情况下,我应该为3个双核8GB RAM服务器提供多少API调用?(假设我的配置有问题)
谢谢
UPDATE
我在两个云服务中分离了API,2合1和1.我仍然在另一个属于Microsoft的IP的Application Insights调用中看到.我认为这是正常的,可能是应用程序洞察无法检测到客户端的真实IP,因为它是一个工作者角色并显示内部角色.
但是,为这么少的电话使用这么多电力的问题仍然存在.有什么想法吗?
azure-worker-roles asp.net-web-api2 azure-cloud-services azure-application-insights
我在Service Fabric 6上有一个Asp.net Core 2.0无状态服务和一个Asp.net Core 2.0状态服务,有10个分区计数.
我按照本教程
https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-add-a-web-frontend
我遵循所有步骤,除了我在Visual Studio中使用模板,其中CreateServiceReplicaListeners使用KestrelCommunicationListener
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
return new ServiceReplicaListener[]
{
new ServiceReplicaListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, (url, listener) =>
{
return new WebHostBuilder()
.UseKestrel()
.ConfigureServices(
services => services
.AddSingleton<StatefulServiceContext>(serviceContext)
.AddSingleton<IReliableStateManager>(this.StateManager))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
.UseUrls(url)
.Build();
}))
};
}
Run Code Online (Sandbox Code Playgroud)
当我使用以下代码在Asp.net Core 2.0无状态服务中调用我的服务时:
var service = ServiceProxy.Create<IStorageService>(new Uri("fabric:/MyCluster/Storage"), new ServicePartitionKey(Fnv1aHashCode.Get64bitHashCode(User.Id)));
await service.MyMethod();
Run Code Online (Sandbox Code Playgroud)
调用"MyMethod"时会出现异常
客户端试图连接到无效的地址的http://本地主机:58352 /等 ..
异常中存在的URL存在于Service Fabric Explorer中,并且Port和PartitionKey是正确的.ServiceManifest中没有设置端点,因为有状态服务基本上只是添加了IService接口和MyMethod方法的模板,如上所述.
我在这里缺少什么?Asp.net Core 2.0的文档不是最新的.
我试图不使用分区,设置 ServicePartitionKey(0)但结果相同.
我不知道该怎么办.
我有一个具有经典配置WebRole + Worker角色的azure Cloud服务.Worker从队列中获取消息,处理它而不是一次删除一次.
我的代码是这样的:
public override void Run()
{
Trace.TraceInformation("Worker is running");
try
{
this.RunAsync(this.cancellationTokenSource.Token).Wait();
}
finally
{
this.runCompleteEvent.Set();
}
}
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 500;
bool result = base.OnStart();
Trace.TraceInformation("WorkerAnalytics has been started");
return result;
}
private async Task RunAsync(CancellationToken cancellationToken)
{
var queue = ....//omitted info for brevity
CloudQueueMessage retrievedMessage = null;
while (!cancellationToken.IsCancellationRequested)
{
try
{
retrievedMessage = await queue.GetMessageAsync();
if (retrievedMessage != null)
{
await ProcessMessage(retrievedMessage);
}
else
{
System.Threading.Thread.Sleep(500);
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个 Asp.net Core 项目,我正在尝试使用 Helm 3 创建用于 Kubernetes 部署的 Azure DevOps Pipeline。
该项目的结构是:
服务器图表服务器 Chart.yaml 控制器等。
当前的构建管道会构建 docker 映像,并将其上传到 Azure 容器注册表。
错误发生在 HelmDeploy 任务 'package' => ChartPath:
这是部署的管道阶段:
- stage: 'Deploy'
displayName: 'Deploy the container'
dependsOn: Build
jobs:
- deployment: Deploy
displayName: Deploy
pool:
vmImage: 'ubuntu-latest'
environment: 'staging'
strategy:
runOnce:
deploy:
steps:
- task: HelmInstaller@0
inputs:
helmVersion: 'latest'
installKubectl: true
- task: HelmDeploy@0
inputs:
command: 'package'
chartPath: Server/charts/server
- task: HelmDeploy@0
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceConnection: 'Staging-592588480'
namespace: 'staging' …Run Code Online (Sandbox Code Playgroud)