Search code examples
amazon-web-servicesamazon-ec2ws

Sockets taking too much time to connect after sometime on AWS EC2 (t3a.small)


I've deployed ws sockets on Amazon EC2 t3a.small instance. When I start/restarts the sockets it works perfectly fine for sometime. But after few minutes when I try to connect to the sockets it's taking more then a minute to connect and sometimes trigger timeout.

So I changed the instance to t3a.medium and now it's working pretty well. And I'm not seeing any delay in connecting/timeout to the sockets even after couple of hours.

When I check the performance of both the instances the RAM/CAPU usage is not that much. RAM usage is around ~300mb and also not reaching 100% CPU usage for both cores. So I'm not sure what could be the issue.

I don't think updating the instance type is right and scalable solution , As traffic increases I assume I would face the same issue ?

I want to know what is the bottleneck and what configuration I need to set in EC2 which is scalable ?


Update:

It seems the instance size is not an issue. Even after changing it to t3a.medium it slowed down after sometime. So figuring out what could be the issue.


Solution

  • Apparently there was an issue with the Apache2 setting which was allowing maximum 150 concurrent connections.

    So I adjusted Apache httpd to allow for more concurrent connections.

    <IfModule mpm_event_module>
     StartServers 10
     MinSpareThreads 25
     MaxSpareThreads 750
     ThreadLimit 1000
     ThreadsPerChild 750
    # MaxRequestWorkers aka MaxClients => ServerLimit *ThreadsPerChild
     MaxRequestWorkers 15000
     MaxConnectionsPerChild 0
     ServerLimit 20
     ThreadStackSize 524288
    </IfModule>
    

    Please note you may also need to change max open files of OS. By default it's 1024 in Ubuntu. Set it to MAX (65536)