Permalink
Browse files

misc:add comment and readme

  • Loading branch information...
piaohai committed Aug 22, 2012
1 parent e08ed60 commit a787c428d57b8407764d95c1b71288667f5a33d4
View
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2012 Netease, Inc. and other pomelo contributors
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,69 @@
+#pomelo-robot
+pomelo-robot is simple tool to benchmark the socket.io server performance.
+
+pomelo-robot can run in multiple mode such as single machine with many process
+,distribute test many socket.io server.
+
+pomelo-robot execute developer custom JavaScript in a sand box and static
+monitor include max(min,avg) response time and QPS,etc. then report to web http
+server with graph display
+
+pomelo-robot also can be used in http benchmark by developer script;
+
+
+##Installation
+```
+npm install pomelo-robot
+```
+
+##Usage
+``` javascript
+
+var Robot = require('pomelo-robot').Robot;
+//developer custom data source with data application
+var queryHero = require('./app/data/mysql').queryHero;
+//config the master and app,detail by demo
+var config = require('./app/config/config');
+var fs = require('fs');
+
+var robot = new Robot(config);
+
+if (robot.server==='master') {
+ robot.run(__filename);
+} else {
+ var mysql =config[robot.env].mysql;
+ var Client = require('mysql').Client;
+ var client = new Client();
+ client.host = mysql.host;
+ client.user = mysql.user;
+ client.password = mysql.password;
+ client.database = mysql.database;
+ var args = process.argv;
+ var i = 5;
+ var limit = args[i++];
+ var offset= args[i++];
+ //developer execute script
+ var script = fs.readFileSync(process.cwd() + '/app/config/lord.js', 'utf8');
+ queryHero(client,limit,offset,function(error,users){robot.run(users,script)});
+}
+
+```
+
+##API
+###robot.runMaster()
+run master server and http server,then initial server status include
+clients,start up file.
+####Arguments
++ startUpFile - The master server auto start up agent file name, default is
+ current run file;
+
+###robot.runAgent()
+robot run in client agent mode.
+####Arguments
++ datasource - The Array data ,and the size is the concurrent users.
++ script - The developer custom script that agent should be execute.
+
+###Notice
+when pomelo-robot run in distribute mode, every client should be in same
+directory path and master could be ssh login automatic. Otherwise developer can
+start up agent by self,for the custom script, the demo is attachment.
View
@@ -4,11 +4,18 @@ var logging = require('../common/logging').Logger;
var Machine = require('./machine').Machine;
var monitor = require('../monitor/monitor');
-var STATUS_INTERVAL = 60 * 1000; // 60 seconds
+var STATUS_INTERVAL = 10 * 1000; // 60 seconds
var RECONNECT_INTERVAL = 15 * 1000; // 15 seconds
var HEARTBEAT_PERIOD = 30 * 1000; // 30 seconds
var HEARTBEAT_FAILS = 5; // Reconnect after 3 missed heartbeats
+/**
+ *
+ * @param {Object} conf
+ * init the master and app server for the agent
+ * include app data, exec script,etc.
+ *
+ */
var Agent = function(conf) {
this.log = logging;
this.conf = {};
@@ -26,7 +33,6 @@ var Agent = function(conf) {
};
Agent.prototype = {
-
// Create socket, bind callbacks, connect to server
connect: function() {
var agent = this;
@@ -90,7 +96,7 @@ Agent.prototype = {
setInterval(function(){
var d = monitor.getData();
agent.socket.emit('report',{id:agent.nodeId,data:d});
- },5000);
+ },STATUS_INTERVAL);
},
close:function(){
View
@@ -5,7 +5,13 @@ var fs = require('fs');
var io = require('socket.io-client');
var Robot = require('./robot').Robot;
-
+/**
+ *
+ *create machin instance
+ * @param {Object} app location,
+ * @param {Array} test case data
+ * @param {String} script
+ */
var Machine = function(app,user,script) {
EventEmitter.call(this);
this.conf = {};
View
@@ -54,17 +54,21 @@ var pro = Robot.prototype;
/**
- *对延时操作的封装
+ * emit done event
+ *
*/
pro.done = function(){
//process.exit();
this.emit('done',this.user.uid);
};
/**
- * 对发送数据的emit封装
+ * wrap socket.io emit message
+ *
+ *@param {Object} msg
+ *
*/
-pro.pushMessage = function(msg,watched){
+pro.pushMessage = function(msg){
//console.error('pushMessage message ' + JSON.stringify(msg));
var self = this;
if(!!msg)
@@ -74,7 +78,12 @@ pro.pushMessage = function(msg,watched){
var cbs = {};
/**
- * 对发送数据的send封装
+ *wrap socket.io send message
+ *
+ * @param {String} msg
+ * @param {Function} cb
+ * @param {Boolean} encdoe
+ *
*/
pro.request = function(msg,cb,encode){
var self = this;
@@ -90,7 +99,10 @@ pro.request = function(msg,cb,encode){
};
/**
- *对延时操作的封装
+ * wrap setTimeout
+ *
+ *@param {Function} fn
+ *@param {Number} time
*/
pro.later = function(fn,time){
if (time>0 && typeof(fn)=='function') {
@@ -99,10 +111,12 @@ pro.later = function(fn,time){
};
/**
+ * wrap setInterval
+ * when time is Array, the interval time is thd random number
+ * between then
*
- * 对interval操作的封装,
- * time为数组时,interval的时间为数组期间的随机数
- *
+ *@param {Function} fn
+ *@param {Number} time
*/
pro.interval = function(fn,time){
var fn = arguments[0];
@@ -123,13 +137,25 @@ pro.interval = function(fn,time){
}
};
-
-pro.clean = function(timeId){
- clearTimeOut(timeId);
+/**
+ *wrap clearTimeout
+ *
+ * @param {Number} timerId
+ *
+ */
+pro.clean = function(timerId){
+ clearTimeOut(timerId);
}
var id=1;
+/**
+ *encode message
+ *
+ * @param {Number} id
+ * @param {Object} msg
+ *
+ */
pro.encode = function(id,msg) {
return Protocol.encode(id,msg.route,msg);
}
View
@@ -8,8 +8,8 @@
*/
var Logger = function(log_level) {
- this._log_level = log_level ? log_level : 2
-}
+ this._log_level = log_level ? log_level : 2;
+};
Logger.prototype = {
_timestamp: function(msg) {
@@ -22,8 +22,7 @@ Logger.prototype = {
},
isDebug: function(msg) {
- if (this._log_level < 3) { return;false } else {return true;}
-
+ if (this._log_level < 3) { return false; } else {return true;}
},
info: function(msg) {
@@ -48,4 +47,4 @@ getLogger = function() {
return instance();
};
-exports.Logger = instance;
+exports.Logger = instance;
View
@@ -15,11 +15,11 @@ var EventEmitter = require('events').EventEmitter;
// A few common global functions so we can access them with as few keystrokes as possible
//
var qputs = util.qputs = function(s) {
- { util.puts(s); }
+ util.puts(s);
};
var qprint = util.qprint = function(s) {
- { util.print(s); }
+ util.print(s);
};
@@ -45,13 +45,15 @@ util.extend = function(obj, extension) {
}
return obj;
};
+
util.forEach = function(obj, f) {
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
f(i, obj[i]);
}
}
};
+
util.every = function(obj, f) {
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
@@ -153,4 +155,4 @@ util.LineReader = function(eventEmitter, event) {
}
util.inherits(util.LineReader, EventEmitter);
-util.extend(exports, util);
+util.extend(exports, util);
View
@@ -1,5 +1,5 @@
// ------------------------------------
-// HTTP Server hello git
+// HTTP Server
// ------------------------------------
//
// This file defines HttpServer and the singleton HTTP_SERVER.
View
@@ -1,6 +1,6 @@
<html>
<head>
-<title>Pomelo Console</title>
+<title>Pomelo Robot Console</title>
<link rel="stylesheet" type="text/css" href="css/web_client.css" />
<link rel="stylesheet" type="text/css" href="css/colors.css" />
<script src="/js/lib/jquery.min.js"></script>
@@ -106,14 +106,12 @@
</div>
<div id='summary_div' style='display:none'></div>
-
- <!-- #stream_template -->
<div class="screen history" id="avg_div2" style="height:246px">
<div class="bar">
<span class="screen-label">响应时间表</span>
<div class="bar-top-right">
<div class="screen-buttons"><input type="button" class="add-button"
- id='avgbtn'" value='查看Agent'>&nbsp;<img id='avg_img' style='display:none'
+ id='avgbtn' value='查看Agent'>&nbsp;<img id='avg_img' style='display:none'
src="/images/icons/cross.png" title="Close Screen" />
</div>
<div class="screen-search">
@@ -127,7 +125,6 @@
</div>
<div id='avg_div' style='display:none'></div>
-
<div class="screen history" id="qs_div2" style="height:246px">
<div class="bar">
<span class="screen-label">吞吐率图表</span>
@@ -147,9 +144,6 @@
</div>
<div id='qs_div' style='display:none'></div>
-
- <!-- #history_template -->
-
<div id="bottom">
<div id="bottom2">
<div id="stats">
Oops, something went wrong.

0 comments on commit a787c42

Please sign in to comment.