Traffic Simulator
- generate mock traffic
- for now just GET requests
API
Basics
const TrafficSimulator SECOND = ;const graph = /* see below */ ; const opts = delayRate: 1 * SECOND minDepth: 2 maxDepth: 20 minTmOnPage: 1 * SECOND maxTmOnPage: 30 * SECOND nClients: 50 doLog: true; const ts = graph opts;ts;
Default Options
const MILLISEC = 1;const SECOND = 1000 * MILLISEC; const DEFAULTS = nClients: 10 delayRate: 1 * SECOND // time between clients are spawned minTmOnPage: 3 * SECOND maxTmOnPage: 120 * SECOND maxDepth: 20 // max #clicks that each client makes minDepth: 2 doLog: true
Overridable Methods (via Inheritance)
protected get randURL: string; // start URL when creating a new client workerprotected get randDepth: number; // length of new client worker tourprotected get randTmOnPg: number; // time on the current page after each transition protected nameFunctidx: number: string; // name for new client workersprotected warnmsg: Printable: void; // defaults to console.warnprotected logmsg: Printable: void; // defaults to console.log // You will have access to all opts: this.nClients, this.delayRate ...
EventEmitter API
The following events are emitted along with the data specified in parenthesis.
- randURL(url: string)
- depth(workerName: string)
- exit(workerName: string)
- null(workerName: string)
- spent(workerName: string, url: string, timeSpent: number)
- spawn({ workerName: string, url: string, depth: number }, atTime: Date)
Link Graph
For a complete example see examples/simple.ts
.
// adjacency list (floats are transition PROBABILITIES, they MUST add up to 1.0)// // stackoverflow => google (p = .2)// stackoverflow => exit (p = .8)// news.ycombinator => news.ycombinator => .2// news.ycombinator => exit (p = .8)// // etc.const EXAMPLE_GRAPH = 'https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep': 'https://www.google.co.uk/search?newwindow=1&source=hp&ei=cVDHXPOtF5HosAfKnJrgDw&q=javascript+sleep+await&oq=jav&gs_l=psy-ab.1.0.35i39l2j0i20i263j0j0i131j0j0i20i263j0i131j0j0i131.889.1455..2407...0.0..0.131.347.3j1......0....1..gws-wiz.....0.8oIEbZdX7Es': 02 '%exit%': 08 'https://news.ycombinator.com/': 'https://news.ycombinator.com/news?p=2': 02 '%exit%': 08 'https://news.ycombinator.com/news?p=2': 'https://news.ycombinator.com/news?p=3': 01 '%exit%': 09 'https://www.google.co.uk/search?newwindow=1&source=hp&ei=cVDHXPOtF5HosAfKnJrgDw&q=javascript+sleep+await&oq=jav&gs_l=psy-ab.1.0.35i39l2j0i20i263j0j0i131j0j0i20i263j0i131j0j0i131.889.1455..2407...0.0..0.131.347.3j1......0....1..gws-wiz.....0.8oIEbZdX7Es': 'https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep': 08 'https://flaviocopes.com/javascript-sleep/': 02 'https://github.com/': 'https://github.com/': 04 'https://github.com/search?utf8=%E2%9C%93&q=node&type=': 05 '%exit%': 01 'https://www.w3schools.com/jsref/met_win_settimeout.asp': 'https://www.w3schools.com/jsref/prop_win_opener.asp': 01 'https://www.w3schools.com/jsref/prop_win_sessionstorage.asp': 02 '%exit%': 07 'https://github.com/search?utf8=%E2%9C%93&q=node&type=': 'https://github.com/nodejs/node': 06 '%exit%': 04 ;