I currently have a C# application running as a windows service. The app starts up a TCPListener, then in a while loop grabs the clients and immediately throws them to a ThreadPool.UnsafeQueueUserWorkItem to do all the actual work. The client is closed at the end of the UnsageQueueUserWorkItem call. The basic code is below:
var server = new TcpListener(ip, port);
server.Start();
while (true)
{
try
{
TcpClient client = await server.AcceptTcpClientAsync();
var cw = new TcpClientService(logger, client, parser, dataRepo, propertyRecordDefinitions,
vimAlertsSent, reservations, emailClient);
ThreadPool.UnsafeQueueUserWorkItem(x => ((TcpClientService)x).Run(), cw);
}
catch(Exception iex)
{
//DO SOME LOGGING
}
finally
{
}
}
This all runs as a windows service on a VM in AWS. Im wondering if this is a good candidate for Google Cloud Run (or any other serverless/stateless function). I am getting hundreds of requests (clients) a minute and am hoping to scale to thousands. As I understand it, Cloud Run could potentially be triggered by the incoming request, then I could just run my TcpClientService code that is currently being called by the Threadpool.UnsafeQueueUserWorkItem. Is this a good implementation? Is this what Google Cloud Run is optimized for? I am wondering if I will see some degradation in that DB connections may not be pooled, and some other structures I share across the threads (all my inputs to the TcpClientService call) would have to be newed up each function call. Thoughts?