Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,14 @@ async Task RegisterMachine(IOctopusSystemAsyncRepository systemRepository, IOcto
}

configuration.Value.AddOrUpdateTrustedOctopusServer(server);
configuration.Value.SetIsWorker(IsRegisteredAsWorker);
VoteForRestart();

log.Info("Machine registered successfully");
}

protected virtual bool IsRegisteredAsWorker => false;

protected abstract void CheckArgs();

protected abstract void EnhanceOperation(TRegistrationOperationType registerOperation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public RegisterWorkerCommandBase(Lazy<TRegisterWorkerOperation> lazyRegisterMach
Options.Add("workerpool=", "The worker pool name, slug or Id to add the machine to - e.g., 'Windows Pool'; specify this argument multiple times to add to multiple pools", s => workerpools.Add(s));
}

protected override bool IsRegisteredAsWorker => true;

protected override void CheckArgs()
{
if (workerpools.Count == 0 || string.IsNullOrWhiteSpace(workerpools.First()))
Expand Down
12 changes: 7 additions & 5 deletions source/Octopus.Tentacle/Communications/HalibutInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,21 @@ void AddPollingEndpoints()
}
}

const int MaximumPollingConnectionCount = 8;

const uint MinimumPollingConnectionCount = 2;
const uint MaximumPollingConnectionCount = 8;

uint GetPollingConnectionCount()
{
//Open multiple polling connections if the env var is set to a non-zero/negative number
var connectionCount = 1u;
// Default to one connection per CPU core (clamped to [min, max]) for workers; deployment targets stay at 1
var connectionCount = configuration.IsWorker
? (uint)Math.Clamp(Environment.ProcessorCount, MinimumPollingConnectionCount, MaximumPollingConnectionCount)
: 1u;
if (uint.TryParse(Environment.GetEnvironmentVariable(EnvironmentVariables.TentaclePollingConnectionCount), out var count))
{
log.InfoFormat("Requested polling connection count: {0}", count);
connectionCount = count;
}

//Coerce the requested value as it might be outside our max & min
switch (connectionCount)
{
case > MaximumPollingConnectionCount:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public interface ITentacleConfiguration

bool IsRegistered { get; }

bool IsWorker { get; }

void WriteTo(IWritableKeyValueStore outputStore, IEnumerable<string> excluding);
}

Expand All @@ -92,6 +94,8 @@ public interface IWritableTentacleConfiguration : ITentacleConfiguration

bool SetIsRegistered(bool isRegistered = true);

bool SetIsWorker(bool isWorker = true);

/// <summary>
/// Sets the IP address to listen on.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Octopus.Tentacle.Configuration
internal class TentacleConfiguration : ITentacleConfiguration
{
internal const string IsRegisteredSettingName = "Tentacle.Services.IsRegistered";
internal const string IsWorkerSettingName = "Tentacle.Services.IsWorker";
internal const string ServicesPortSettingName = "Tentacle.Services.PortNumber";
internal const string ServicesListenIPSettingName = "Tentacle.Services.ListenIP";
internal const string ServicesNoListenSettingName = "Tentacle.Services.NoListen";
Expand Down Expand Up @@ -70,6 +71,8 @@ public IEnumerable<string> TrustedOctopusThumbprints

public bool IsRegistered => settings.Get(IsRegisteredSettingName, false);

public bool IsWorker => settings.Get(IsWorkerSettingName, false);

public void WriteTo(IWritableKeyValueStore outputStore, IEnumerable<string> excluding)
{
excluding = new HashSet<string>(excluding);
Expand Down Expand Up @@ -191,6 +194,11 @@ public bool SetIsRegistered(bool isRegistered = true)
return settings.Set(IsRegisteredSettingName, isRegistered);
}

public bool SetIsWorker(bool isWorker = true)
{
return settings.Set(IsWorkerSettingName, isWorker);
}

public bool SetListenIpAddress(string? address)
{
return settings.Set(ServicesListenIPSettingName, address);
Expand Down