Update orleans cluster config
This commit is contained in:
@@ -93,8 +93,25 @@ public static class ApiBootstrap
|
|||||||
var disableOrleansClustering = !string.IsNullOrEmpty(disableOrleansClusteringEnv) &&
|
var disableOrleansClustering = !string.IsNullOrEmpty(disableOrleansClusteringEnv) &&
|
||||||
bool.TryParse(disableOrleansClusteringEnv, out var disabled) && disabled;
|
bool.TryParse(disableOrleansClusteringEnv, out var disabled) && disabled;
|
||||||
|
|
||||||
|
// Get TASK_SLOT for multi-instance configuration
|
||||||
|
var taskSlotEnv = Environment.GetEnvironmentVariable("TASK_SLOT");
|
||||||
|
var taskSlot = 1; // Default to 1 if not provided
|
||||||
|
if (!string.IsNullOrEmpty(taskSlotEnv) && int.TryParse(taskSlotEnv, out var parsedTaskSlot))
|
||||||
|
{
|
||||||
|
taskSlot = parsedTaskSlot;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate unique ports based on task slot
|
||||||
|
var siloPort = 11111 + (taskSlot - 1) * 10; // 11111, 11121, 11131, etc.
|
||||||
|
var gatewayPort = 30000 + (taskSlot - 1) * 10; // 30000, 30010, 30020, etc.
|
||||||
|
var dashboardPort = 9999 + (taskSlot - 1); // 9999, 10000, 10001, etc.
|
||||||
|
|
||||||
var postgreSqlConnectionString = configuration.GetSection("PostgreSql")["Orleans"];
|
var postgreSqlConnectionString = configuration.GetSection("PostgreSql")["Orleans"];
|
||||||
|
|
||||||
|
Console.WriteLine($"Silo port: {siloPort}");
|
||||||
|
Console.WriteLine($"Gateway port: {gatewayPort}");
|
||||||
|
Console.WriteLine($"Dashboard port: {dashboardPort}");
|
||||||
|
|
||||||
return hostBuilder.UseOrleans(siloBuilder =>
|
return hostBuilder.UseOrleans(siloBuilder =>
|
||||||
{
|
{
|
||||||
// Configure clustering with improved networking or use localhost clustering if disabled
|
// Configure clustering with improved networking or use localhost clustering if disabled
|
||||||
@@ -123,33 +140,37 @@ public static class ApiBootstrap
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure networking - simplified for Docker compatibility
|
// Configure networking - simplified for Docker compatibility with unique ports per instance
|
||||||
if (disableOrleansClustering)
|
if (disableOrleansClustering)
|
||||||
{
|
{
|
||||||
// Use localhost clustering when clustering is disabled
|
// Use localhost clustering when clustering is disabled
|
||||||
siloBuilder.ConfigureEndpoints(IPAddress.Loopback, 11111, 30000);
|
siloBuilder.ConfigureEndpoints(IPAddress.Loopback, siloPort, gatewayPort);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Use localhost for development, proper hostname for production
|
// Use localhost for development, proper hostname for production
|
||||||
if (isProduction)
|
if (isProduction)
|
||||||
{
|
{
|
||||||
// In production, use all interfaces
|
// In production, use all interfaces with unique ports per instance
|
||||||
siloBuilder.ConfigureEndpoints(IPAddress.Any, 11111, 30000);
|
siloBuilder.ConfigureEndpoints(IPAddress.Any, siloPort, gatewayPort);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// In development, use localhost
|
// In development, use localhost with unique ports per instance
|
||||||
siloBuilder.ConfigureEndpoints(IPAddress.Loopback, 11111, 30000);
|
siloBuilder.ConfigureEndpoints(IPAddress.Loopback, siloPort, gatewayPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
siloBuilder
|
siloBuilder
|
||||||
.Configure<ClusterOptions>(options =>
|
.Configure<ClusterOptions>(options =>
|
||||||
{
|
{
|
||||||
// Configure cluster options with unique identifiers
|
// Configure cluster options with unique identifiers including task slot
|
||||||
options.ServiceId = "ManagingApp";
|
options.ServiceId = "ManagingApp";
|
||||||
options.ClusterId = configuration["ASPNETCORE_ENVIRONMENT"] ?? "Development";
|
options.ClusterId = configuration["ASPNETCORE_ENVIRONMENT"] ?? "Development";
|
||||||
|
|
||||||
|
// Add task slot to silo identity for better tracking
|
||||||
|
var siloName = $"ManagingApi-{taskSlot}";
|
||||||
|
// Orleans will use this for internal identification
|
||||||
})
|
})
|
||||||
.Configure<MessagingOptions>(options =>
|
.Configure<MessagingOptions>(options =>
|
||||||
{
|
{
|
||||||
@@ -204,8 +225,8 @@ public static class ApiBootstrap
|
|||||||
{
|
{
|
||||||
siloBuilder.UseDashboard(options =>
|
siloBuilder.UseDashboard(options =>
|
||||||
{
|
{
|
||||||
// Configure dashboard with proper shutdown handling
|
// Configure dashboard with proper shutdown handling and unique ports per instance
|
||||||
options.Port = 9999;
|
options.Port = dashboardPort;
|
||||||
options.HostSelf = true;
|
options.HostSelf = true;
|
||||||
options.CounterUpdateIntervalMs = 10000; // 10 seconds
|
options.CounterUpdateIntervalMs = 10000; // 10 seconds
|
||||||
options.HideTrace = true; // Hide trace to reduce dashboard overhead
|
options.HideTrace = true; // Hide trace to reduce dashboard overhead
|
||||||
|
|||||||
Reference in New Issue
Block a user