Skip to content
Snippets Groups Projects
Commit 33e276d2 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[Ivette/server] fix internal state

parent 918b2292
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ import Zmq from 'zeromq' ; ...@@ -23,7 +23,7 @@ import Zmq from 'zeromq' ;
@event @event
@summary Server Status Notification Event @summary Server Status Notification Event
@description @description
Event `'frama-c.server`. Event `'frama-c.server'`.
*/ */
export const SERVER = 'frama-c.server' ; export const SERVER = 'frama-c.server' ;
...@@ -62,11 +62,8 @@ var queue_cmd; // Queue of server commands to be sent ...@@ -62,11 +62,8 @@ var queue_cmd; // Queue of server commands to be sent
var queue_ids; // Waiting request ids to be sent var queue_ids; // Waiting request ids to be sent
var polling; // Timeout Polling timer var polling; // Timeout Polling timer
var flushed; // Immediate Flushed timer var flushed; // Immediate Flushed timer
var config; // Server process config var config; // Server config
var sent; // Characters sent var process; // Server process
var recv; // Characters received
var started; // Date of Server activity start
var process; // Cumulated Server processing time
var socket; // ZMQ (REQ) socket var socket; // ZMQ (REQ) socket
var busy; // ZMQ socket is busy var busy; // ZMQ socket is busy
var killer; // killer timeout var killer; // killer timeout
...@@ -99,25 +96,11 @@ export function getError() { return error; } ...@@ -99,25 +96,11 @@ export function getError() { return error; }
export function isRunning() { return status === RUNNING; } export function isRunning() { return status === RUNNING; }
/** /**
@summary Server Statistics. @summary Number of requests still pending.
@return {object} stats (see above) @return {number} pending requests
@description
The returned object has the following properties:
- `pending` : number of pending requests;
- `requests` : number of issued requests;
- `time` : ellapsed time of server activity, in milliseconds.
- `sent` : number of UTF-8 chars sent to server;
- `recv` : number of UTF-8 chars received from server;
- `rate` : number of requests per milliseconds.
*/ */
export function getStats() { export function getPending() {
const pending = _.reduce( pending , (n,_) => n+1, 0 ); return _.reduce( pending , (_,n) => n+1, 0 );
const requests = rqid - pending ;
const time = process + (started ? Date.now() - started : 0 );
const rate = process ? requests / process : 0 ;
return {
pending, requests, sent, recv, rate, time
};
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -356,11 +339,7 @@ async function _launch() { ...@@ -356,11 +339,7 @@ async function _launch() {
function _reset() { function _reset() {
rqid = 0; rqid = 0;
sent = 0;
recv = 0;
started = undefined;
process = undefined; process = undefined;
started = undefined;
queue_cmd = []; queue_cmd = [];
queue_ids = []; queue_ids = [];
_.forEach( pending , ({ reject }) => reject('shutdown') ); _.forEach( pending , ({ reject }) => reject('shutdown') );
...@@ -491,35 +470,26 @@ function _send() { ...@@ -491,35 +470,26 @@ function _send() {
if (!busy) { if (!busy) {
const cmd = queue_cmd ; const cmd = queue_cmd ;
if (!cmd.length && _waiting()) cmd.push('POLL'); if (!cmd.length && _waiting()) cmd.push('POLL');
if (!cmd.length) { if (cmd.length) {
const ids = queue_ids ; const ids = queue_ids ;
queue_cmd = []; queue_cmd = [];
queue_ids = []; queue_ids = [];
const socket = socket ; const socket = socket ;
if (socket) { if (socket) {
if (!started) started = Date.now() ;
busy = true ; busy = true ;
sent = cmd.reduce( (s,p) => s + p.length , sent);
socket.send( cmd ) socket.send( cmd )
.then(() => socket.receive().then((resp) => _receive(resp))) .then(() => socket.receive().then((resp) => _receive(resp)))
.catch(() => _cancel(ids)) .catch(() => _cancel(ids))
.finally(() => busy = false); .finally(() => { busy = false ; Dome.emit(SERVER); });
} else } else
_cancel(ids); _cancel(ids);
} else { Dome.emit(SERVER);
const started = started ;
if (started) {
const stopped = Date.now();
process += stopped - started ;
started = undefined ;
}
} }
} }
} }
function _receive(resp) { function _receive(resp) {
try { try {
recv = resp.reduce( (s,p) => s + p.length , recv);
var rid,data,err,cmd; var rid,data,err,cmd;
const shift = () => resp.shift().toString(); const shift = () => resp.shift().toString();
while( resp.length ) { while( resp.length ) {
...@@ -571,7 +541,7 @@ function _receive(resp) { ...@@ -571,7 +541,7 @@ function _receive(resp) {
export default { export default {
configure, console, configure, console,
getStatus, getError, getStats, isRunning, getStatus, getError, getPending, isRunning,
start, stop, kill, restart, clear, start, stop, kill, restart, clear,
sendGET, sendSET, sendEXEC, sendGET, sendSET, sendEXEC,
IDLE,STARTED,RUNNING,KILLING,RESTART,FAILED IDLE,STARTED,RUNNING,KILLING,RESTART,FAILED
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment