 			)
 			VALUES
 			(
-				_deploymentId,
-				_siloId,
-				_address,
-				_port,
-				_generation,
-				_hostName,
-				_gatewayAddress,
-				_gatewayPort,
-				_cpuUsage,
-				_memoryUsage,
-				_activationsCount,
-				_recentlyUsedActivationsCount,
-				_sendQueueLength,
-				_receiveQueueLength,
-				_requestQueueLength,
-				_sentMessagesCount,
-				_receivedMessagesCount,
-				_isOverloaded,
-				_clientCount
-			);
-		END IF;
-		COMMIT;
-END$$    
-
-DELIMITER ;
+				@deploymentId,
+				@siloId,
+				@address,
+				@port,
+				@generation,
+				@hostName,
+				@gatewayAddress,
+				@gatewayPort,
+				@cpuUsage,
+				@memoryUsage,
+				@activationsCount,
+				@recentlyUsedActivationsCount,
+				@sendQueueLength,
+				@receiveQueueLength,
+				@requestQueueLength,
+				@sentMessagesCount,
+				@receivedMessagesCount,
+				@isOverloaded,
+				@clientCount
+			)
+		ON DUPLICATE KEY UPDATE 
+				Address 		= @address,
+				Port 			= @port,
+				Generation 		= @generation,
+				HostName 		= @hostName,
+				GatewayAddress	 	= @gatewayAddress,
+				GatewayPort		= @gatewayPort,
+				CPU 			= @cpuUsage,
+				Memory 			= @memoryUsage,
+				Activations 		= @activationsCount,
+				RecentlyUsedActivations	= @recentlyUsedActivationsCount,
+				SendQueue 		= @sendQueueLength,
+				ReceiveQueue 		= @receiveQueueLength,
+				RequestQueue 		= @requestQueueLength,
+				SentMessages 		= @sentMessagesCount,
+				ReceivedMessages 	= @receivedMessagesCount,
+				LoadShedding 		= @isOverloaded,
+				ClientCount 		= @clientCount;
+');
 
 INSERT INTO OrleansQuery(QueryKey, QueryText)
 VALUES

			)
			VALUES
			(
				_deploymentId,
				_clientId,
				_address,
				_hostName,
				_cpuUsage,
				_memoryUsage,
				_sendQueueLength,
				_receiveQueueLength,
				_sentMessagesCount,
				_receivedMessagesCount,
				_connectedGatewaysCount
			);
		END IF;
		COMMIT;
END$$    

DELIMITER ;

INSERT INTO OrleansQuery(QueryKey, QueryText)
VALUES
(
	'UpsertSiloMetricsKey','call UpsertSiloMetricsKey(@deploymentId, @siloId, @address, @port, @generation, 
    @hostName, @gatewayAddress, @gatewayPort, @cpuUsage, @memoryUsage, @activationsCount, @recentlyUsedActivationsCount,
	@sendQueueLength, @receiveQueueLength, @requestQueueLength, @sentMessagesCount, @receivedMessagesCount,
	@isOverloaded, @clientCount);'
);

DELIMITER $$

CREATE PROCEDURE UpsertSiloMetricsKey(
	in	_deploymentId NVARCHAR(150),
	in	_siloId NVARCHAR(150),
    in	_timestamp DATETIME,
    in	_address VARCHAR(45),
    in	_port INT,
    in	_generation INT,
    in	_hostName NVARCHAR(150),
    in	_gatewayAddress VARCHAR(45),
    in	_gatewayPort INT,
    in	_cpuUsage FLOAT,
    in	_memoryUsage BIGINT,
    in	_activationsCount INT,
    in	_recentlyUsedActivationsCount INT,
    in	_sendQueueLength INT,
    in	_receiveQueueLength INT,
    in	_requestQueueLength BIGINT,
    in	_sentMessagesCount BIGINT,
	in	_receivedMessagesCount BIGINT,
    in	_isOverloaded BIT,
    in	_clientCount BIGINT
)
BEGIN
		START TRANSACTION;
		IF EXISTS(SELECT 1 FROM  OrleansSiloMetricsTable WHERE
			DeploymentId = _deploymentId AND _deploymentId IS NOT NULL
			AND SiloId = _siloId AND _siloId IS NOT NULL
			FOR UPDATE)
		THEN
			UPDATE OrleansSiloMetricsTable
			SET
				Address = _address,
				Port = _port,
				Generation = _generation,
				HostName = _hostName,
				GatewayAddress = _gatewayAddress,
				GatewayPort = _gatewayPort,
				CPU = _cpuUsage,
				Memory = _memoryUsage,
				Activations = _activationsCount,
				RecentlyUsedActivations = _recentlyUsedActivationsCount,
				SendQueue = _sendQueueLength,
				ReceiveQueue = _receiveQueueLength,
				RequestQueue = _requestQueueLength,
				SentMessages = _sentMessagesCount,
				ReceivedMessages = _receivedMessagesCount,
				LoadShedding = _isOverloaded,
				ClientCount = _clientCount
			WHERE
				(DeploymentId = _deploymentId AND _deploymentId IS NOT NULL)
				AND (SiloId = _siloId AND _siloId IS NOT NULL);
		ELSE
			INSERT INTO OrleansSiloMetricsTable
			(
				DeploymentId,

INSERT INTO OrleansQuery(QueryKey, QueryText)
VALUES
(
	'UpsertReminderRowKey', '
			INSERT INTO OrleansRemindersTable
			(
				ServiceId,
