Skip to content

Commit

Permalink
Improved Reflector performance
Browse files Browse the repository at this point in the history
Added HTTP client factory to prevent socket starvation and DNS update failures
Added memory limit to improved garbage collection
  • Loading branch information
winromulus committed Jul 27, 2020
1 parent 2b337bb commit 68575d1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: $(version).$(Rev:r)

variables:
version: 5.1
version: 5.2
buildConfiguration: "Release"
imageRepository: "emberstack/kubernetes-reflector"
DOCKER_CLI_EXPERIMENTAL: "enabled"
Expand Down
15 changes: 0 additions & 15 deletions src/ES.Kubernetes.Reflector.Core/CoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ protected override void Load(ContainerBuilder builder)
{
builder.RegisterGeneric(typeof(ManagedWatcher<,>));
builder.RegisterGeneric(typeof(ManagedWatcher<,,>));


builder.Register(s =>
{
var logger = s.Resolve<ILogger<CoreModule>>();
var inCluster = KubernetesClientConfiguration.IsInCluster();
logger.LogDebug("Building client configuration. Client is in cluster: '{inCluster}'", inCluster);
return inCluster
? KubernetesClientConfiguration.InClusterConfig()
: KubernetesClientConfiguration.BuildConfigFromConfigFile();
}).As<KubernetesClientConfiguration>().SingleInstance();

builder.Register(s => new k8s.Kubernetes(s.Resolve<KubernetesClientConfiguration>())
{HttpClient = {Timeout = TimeSpan.FromMinutes(60)}}).As<k8s.Kubernetes>().As<IKubernetes>();
}
}
}
14 changes: 14 additions & 0 deletions src/ES.Kubernetes.Reflector.Host/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Net.Http;
using System.Reflection;
using Autofac;
using ES.Kubernetes.Reflector.CertManager;
using ES.Kubernetes.Reflector.ConfigMaps;
using ES.Kubernetes.Reflector.Core;
using ES.Kubernetes.Reflector.Secrets;
using k8s;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand Down Expand Up @@ -35,6 +37,18 @@ public void ConfigureServices(IServiceCollection services)
services.AddMediatR(Assembly.GetExecutingAssembly());

services.AddControllers();

services.AddSingleton(KubernetesClientConfiguration.BuildDefaultConfig());
services.AddHttpClient("kubernetes")
.AddTypedClient<IKubernetes>((httpClient, serviceProvider) =>
{
httpClient.Timeout=TimeSpan.FromSeconds(30);
return new k8s.Kubernetes(
serviceProvider.GetRequiredService<KubernetesClientConfiguration>(), httpClient);
})
.ConfigurePrimaryHttpMessageHandler(s =>
s.GetRequiredService<KubernetesClientConfiguration>().CreateDefaultHttpClientHandler())
.AddHttpMessageHandler(KubernetesClientConfiguration.CreateWatchHandler);
}


Expand Down
14 changes: 7 additions & 7 deletions src/helm/reflector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ readinessProbe:
initialDelaySeconds: 5
periodSeconds: 10

resources: {}
resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
limits:
# cpu: 100m
memory: 256Mi
requests:
# cpu: 100m
memory: 128Mi

nodeSelector: {}
# beta.kubernetes.io/arch: amd64
Expand Down

0 comments on commit 68575d1

Please sign in to comment.