Exemple #1
0
        private async Task <bool> SendDataOrHeartbeatToWebSocket(Task <WebSocketReceiveResult> receive, WebSocket webSocket, LiveIndexingPerformanceCollector collector, MemoryStream ms, int timeToWait)
        {
            if (receive.IsCompleted || webSocket.State != WebSocketState.Open)
            {
                return(false);
            }

            var tuple = await collector.Stats.TryDequeueAsync(TimeSpan.FromMilliseconds(timeToWait));

            if (tuple.Item1 == false)
            {
                await webSocket.SendAsync(WebSocketHelper.Heartbeat, WebSocketMessageType.Text, true, Database.DatabaseShutdown);

                return(true);
            }

            ms.SetLength(0);

            using (ContextPool.AllocateOperationContext(out JsonOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ms))
                {
                    writer.WritePerformanceStats(context, tuple.Item2);
                }

            ms.TryGetBuffer(out ArraySegment <byte> bytes);
            await webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, Database.DatabaseShutdown);

            return(true);
        }
Exemple #2
0
        public Task Performance()
        {
            var stats = GetIndexesToReportOn()
                        .Select(x => new IndexPerformanceStats
            {
                Name        = x.Name,
                Performance = x.GetIndexingPerformance()
            })
                        .ToArray();

            using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WritePerformanceStats(context, stats);
                }

            return(Task.CompletedTask);
        }