Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Pomelo robot usage

Robert Watson edited this page Feb 12, 2014 · 5 revisions

pomelo-robot

pomelo-robot is a performance test tool used for testing the pomelo game server framework, also can test performance of the other services based on socket.io or socket. This module can be used standalone or distributed test modes.

Function

This module's function is performance test and analysis for the game project automatically. It provides robot and script to game server, finally outputs performance test and analysis report. Module pomelo-robot runs user-defined JS script in a sandbox. In the process of running, clients will report data to the master node automatically. The master node refine and summarize all the nodes' test data. The master node calculates the average response time and some other statistics, and sends statistic data regularly to the built-in HTTP server to display in the web.

Module structure

Module's internal operating structure is as follows:

"Master" is responsible for collecting all the running data of "Client" and show results.
"Client" is responsible for runnint custom script in multiple sandboxs("User"), reporting running data to the "Master" at the same time.

Example of use

Let's create a Node.js test project. The project directory structure is as shown below:

Installation of dependent libraries:

npm install pomelo-robot

config.json configuration

"config.json" is divided into two kinds of running environments: development(dev) and production(prod) environments. "prod" environment's file content is as follows:

{
  "master": {"host": "127.0.0.1", "port":8888, "webport":8889, "interval":500},
}

"master": master server IP, communication ports with client, web interface port, running a custom JS script's interval(such as: lord.js).

To implement a custom configuration script

In the "env.json", configuring custom script path:
{
  "env": "prod",
  "script": "/app/script/lord.js"
}
To implement custom script "lord.js":
// ...
// check mysql client user and password near line 387
var client = mysql.createConnection ({ ...
// ...
var queryHero = require(cwd + '/app/data/mysql').queryHero;
// ...
function entry(host, port, token, callback) {
  // ...
  // initialize socketClient
  pomelo.init({host: host, port: port, log: true}, function() {
    pomelo.request('connector.entryHandler.entry', {token: token}, function(data) {
	  // ...
      afterLogin(pomelo,data);
    });
  });
}
// ...

In "/app/data/mysql.js", the code which is looking for the login roles is as follows:

// ...
queryHero = function(client,limit,offset,cb){
    var users = [];
    var sql = "SELECT User.* FROM User,Player where User.id = Player.userId and User.name like 'pomelo%' limit ? offset ? ";
	// ...
};
// ...

The above code is running in a sandbox. Firstly, a role logins game server. After the role's login, we call the "afterLogin" function. Users can do some follow-up related operations.

The entry file:"app.js"

"app.js" can judge according to launch parameters to start the "master" or "client" services.

var envConfig = require('./app/config/env.json');
var config = require('./app/config/' + envConfig.env + '/config');
//...
if (mode === 'master') {
    robot.runMaster(__filename);
} else {
    var script = (process.cwd() + envConfig.script);
    robot.runAgent(script);
}
// ...

Specific code can refer to pomelo-robot-demo.

Run the test

You can run the following commands to start the "master" service:
"node app.js master"
Open a browser to access "http://masterIp:8889"

You can run the following commands to start the "client" service:
"node app.js client"
Note: You can start "client" services on multiple machines to do performance and stress testing.

Web interface will display the number of "client" which connects to the "master". You can configure the the number of the sandbox for each "client" at the column of "Per Agent Users". You can click on the "Go" button to notify all of the clients began to run. The Web interface will obtain the background data regularly to display.
Running interface as shown below:

Other

Please refer to the source code pomelo-robot

Clone this wiki locally