Skip to content

Benchmark volume of messages server can handle. #21

Description

@AndeYashwanth

I implemented my own chatroom using mongo using php-websocket server.
When I try to send each message every millisecond(using chrome js console setInterval()) from a single socket(user) and found that the server is receiving only between 30-80 messages/sec (which are also being stored in DB).

  • Does it mean the messages are being dropped?
  • How can I fix this?
  • What should be the average no.of messages/sec that the server can handle from a single client and multiple clients?

Here is the part of code for socket->onreceive

$socket->on("receive", function (Client $client, $data) use ($socket, $message_handler, $db_handler) {
    $data = json_decode($data, true);
    if ($user_name = $db_handler->checkUserPermissionToRoomAndGetUsername($client->getUserID(), $data['room_id'])) { //check if user has permission to send message to particular room.
        $message = json_encode(array(
            'username' => $user_name,
            'message' => $data['message'],
            'room_id' => $data['room_id'],
            'message_type' => 'chat_message'
        ));
        if ($db_handler->addMessageToRoom($data['room_id'], $client->getUserID(), json_decode($message, true), $message_id)) {
            $message_handler->sendMessageToRoom($data['room_id'], $message, $socket);
        }
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions