public LegacyEntityCreator(IEntityTemplateProvider templateProvider, ISpatialCommunicator spatialCommunicator, IPrefabFactory <GameObject> prefabFactory, IMutableUniverse universe, IEntityComponentInterestOverridesUpdater entityComponentInterestOverridesUpdater, IInterestedComponentUpdaterProvider interestedComponentUpdaterProvider, WorkerMetrics metrics) { this.templateProvider = templateProvider; this.prefabFactory = new PrefabFactoryMetrics(prefabFactory, metrics); // Associate metrics with the factory this.spatialCommunicator = spatialCommunicator; this.universe = universe; this.entityComponentInterestOverridesUpdater = entityComponentInterestOverridesUpdater; this.interestedComponentUpdaterProvider = interestedComponentUpdaterProvider; entitiesToSpawn = new Dictionary <EntityId, EntitySpawnData>(); knownEntities = new HashSet <EntityId>(); this.metrics = metrics; }
public List <DeviceContentSet> GetNewDevicesForDestination(string destination, int limit) { using (WorkerMetrics.DbCallTimer("GetNewDevicesForDestination")) { var set = new List <DeviceContentSet>(); foreach (var devicePoke in DeviceListsOutboundPokes .Where(poke => poke.Destination == destination && poke.Sent == false) .Take(limit) .OrderBy(poke => poke.StreamId).ToList()) { var contentSet = new DeviceContentSet { device_id = devicePoke.DeviceId, stream_id = devicePoke.StreamId, user_id = devicePoke.UserId, deleted = false }; var json = E2EDeviceKeysJson .SingleOrDefault(devKeys => devKeys.DeviceId == devicePoke.DeviceId && devKeys.UserId == devicePoke.UserId); if (json != null) { contentSet.keys = JObject.Parse(json.KeyJson); } contentSet.device_display_name = Devices.SingleOrDefault(dev => dev.UserId == devicePoke.UserId && dev.DeviceId == devicePoke.DeviceId) ?.DisplayName; set.Add(contentSet); } return(set); } }
public List <EventJsonSet> GetAllNewEventsStream(int fromId, int currentId, int limit) { using (WorkerMetrics.DbCallTimer("GetAllNewEventsStream")) { var set = new List <EventJsonSet>(); foreach (var ev in Events .Where(e => e.StreamOrdering > fromId && e.StreamOrdering <= currentId) .Take(limit) .OrderBy(e => e.StreamOrdering).ToList()) { var js = EventsJson.SingleOrDefault(e => e.EventId == ev.EventId); if (js != null) { set.Add(new EventJsonSet(ev, js.Json, js.FormatVersion)); } } return(set); } }
private static void Main(string[] args) { _config = new ConfigurationBuilder() .AddJsonFile("appsettings.default.json", true, true) .AddJsonFile("appsettings.json", true, true) .AddEnvironmentVariables() .AddCommandLine(args) .Build(); Logger.Setup(_config.GetSection("Logging")); var metricConfig = _config.GetSection("Metrics"); if (metricConfig != null && metricConfig.GetValue <bool>("enabled")) { WorkerMetrics.StartMetrics("federation_worker", metricConfig.GetValue("bindPort", 9150), metricConfig.GetValue <string>("bindHost")); } new FederationSender(_config).Start().Wait(); Console.ReadKey(true); }
public PrefabFactoryMetrics(IPrefabFactory <GameObject> prefabFactory, WorkerMetrics metrics) { this.prefabFactory = prefabFactory; this.metrics = metrics; }
public ThrottledEntityDispatcher(IUniverse universe, IEntitySpawnLimiter spawnLimiter, WorkerMetrics workerMetrics) { this.universe = universe; this.spawnLimiter = spawnLimiter; this.workerMetrics = workerMetrics; }
private async Task AttemptNewTransaction(string destination) { Transaction currentTransaction; if (!_destPendingTransactions.TryGetValue(destination, out currentTransaction)) { log.Debug("No more transactions for {destination}", destination); return; } _destPendingTransactions.Remove(destination); while (true) { using (WorkerMetrics.TransactionDurationTimer()) { try { await concurrentTransactionLock.WaitAsync(); WorkerMetrics.IncOngoingTransactions(); await _client.SendTransaction(currentTransaction); concurrentTransactionLock.Release(); } catch (Exception ex) { WorkerMetrics.DecOngoingTransactions(); concurrentTransactionLock.Release(); log.Warning("Transaction {txnId} {destination} failed: {message}", currentTransaction.transaction_id, destination, ex.Message); var ts = _backoff.GetBackoffForException(destination, ex); WorkerMetrics.IncTransactionsSent(false, destination); // Some transactions cannot be retried. if (ts != TimeSpan.Zero) { log.Information("Retrying txn {txnId} in {secs}s", currentTransaction.transaction_id, ts.TotalSeconds); await Task.Delay((int)ts.TotalMilliseconds); continue; } } } if (_backoff.ClearBackoff(destination)) { log.Information("{destination} has come back online", destination); } ClearDeviceMessages(currentTransaction); WorkerMetrics.DecOngoingTransactions(); WorkerMetrics.IncTransactionsSent(true, destination); WorkerMetrics.IncTransactionEventsSent("pdu", destination, currentTransaction.pdus.Count); WorkerMetrics.IncTransactionEventsSent("edu", destination, currentTransaction.edus.Count); if (!_destPendingTransactions.TryGetValue(destination, out currentTransaction)) { log.Debug("No more transactions for {destination}", destination); return; } _destPendingTransactions.Remove(destination); } }