1

I have two Servers

Server 1 -> AMD Epyc 7371 - 16c/32t - 3.1 GHz/3.8 GHz Ram 256Gb

Server 2 -> 2× Intel Xeon Gold 6242R - 20c/40t - 3.1 GHz/4.1 GHz Ram 384Gb

on both servers I have installed a websocket that is the same in all respects

On server 1 with 20/30 users Client Server calls are fast

On Server 2 with 3 connected users the service is very slow it takes about 10 seconds before the server responds to the client

this is the code

    // SSL context.
    $context = stream_context_create([

        'ssl' => [

            'local_cert' => "./certificate/a2699ad7df6c0f70bde860be9b807edd.crt",
            'local_pk'   => "./certificate/a2699ad7df6c0f70bde860be9b807edd.key",
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false
        ],
    ]);
   

 $socket = stream_socket_server("ssl://".$addrSocket.":".$port."", $errno, $errstr, STREAM_CLIENT_ASYNC_CONNECT| STREAM_SERVER_BIND | STREAM_CLIENT_PERSISTENT| STREAM_SERVER_LISTEN, $context);

    while (1) {

        try
        {
            // look for new connections
            if (($c = stream_socket_accept($socket, empty($connections) ? -1 : 0, $peer)) && $info = handshake($c)) {

                $connections[$peer] = $c;
                $data = (new \DateTime())->format('Y-m-d H:i:s');
                stdout('Open - online: '.count($connections).' - '.$peer.' - '.$data);
            }

            // wait for any stream data
            if(count($connections) > 0){

                $read = $connections;
                if (stream_select($read, $write, $except, 10)) {

                    foreach ($read as $c) {

                        $peer = stream_socket_get_name($c, true);

                        if (feof($c)) {

                            $data = (new \DateTime())->format('Y-m-d H:i:s');

                            if(isset($connections[$peer])){unset($connections[$peer]);}

                            stream_socket_shutdown($c, STREAM_SHUT_RDWR);
                            stdout('Close '.$peer.' - '.$data);
                        }
                        else {

                            $contents = fread($c, $maxBufferSize);
                            $resp_ = onMessage($c, $contents, $peer, $addrProcess, $useCertificate, $opId, $contents);

                            $mode = $resp_['mode'];
                            $opId = $resp_['opId'];
                            $contents = $resp_['contents'];

                            if($mode == "close"){

                                $gid = "**";

                                if(isset($connections[$peer])){unset($connections[$peer]);}

                                stream_socket_shutdown($c, STREAM_SHUT_RDWR);

                                $data = (new \DateTime())->format('Y-m-d H:i:s');
                                stdout('rClose '.$peer.' - '.$data.' - '.$gid);
                            }
                        }
                    }
                }
            }
        }
        catch (Exception $e)
        {
            stdout('Caught exception: '.$e->getMessage());
        }
    }

TCP ports are set to 65000 on both servers, MySql 8.0 is installed on both servers

with the same configurations.

The difference is the processor how can I fix it? Thanks

3
  • have you measured CPU, Memory, Processes usage ? maybe a background task on server #2 ? Commented May 11, 2023 at 23:05
  • the CPU is very very low about 3% and memory used 4% the late, up to 10 seconds can pass between the call to the socket and the response Commented May 12, 2023 at 2:35
  • Additional DB information request from Server 2, please. OS, Version? RAM size, # cores, any SSD or NVME devices on MySQL Host server? Post TEXT data on justpaste.it and share the links. From your SSH login root, Text results of: A) SELECT COUNT(*), sum(data_length), sum(index_length), sum(data_free) FROM information_schema.tables; B) SHOW GLOBAL STATUS; after minimum 24 hours UPTIME C) SHOW GLOBAL VARIABLES; D) SHOW FULL PROCESSLIST; E) STATUS; not SHOW STATUS, just STATUS; G) SHOW ENGINE INNODB STATUS; for server workload tuning analysis to provide suggestions. Commented May 12, 2023 at 21:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.