diff options
Diffstat (limited to 'js/demo/Ice/latency')
-rw-r--r-- | js/demo/Ice/latency/.gitignore | 1 | ||||
-rw-r--r-- | js/demo/Ice/latency/Client.js | 91 | ||||
-rw-r--r-- | js/demo/Ice/latency/Latency.ice | 19 | ||||
-rw-r--r-- | js/demo/Ice/latency/Makefile | 16 | ||||
-rw-r--r-- | js/demo/Ice/latency/Makefile.mak | 16 | ||||
-rw-r--r-- | js/demo/Ice/latency/README | 21 | ||||
-rw-r--r-- | js/demo/Ice/latency/browser/Client.js | 161 | ||||
-rw-r--r-- | js/demo/Ice/latency/build.js | 10 | ||||
-rwxr-xr-x | js/demo/Ice/latency/expect.py | 36 | ||||
-rw-r--r-- | js/demo/Ice/latency/index.html | 139 |
10 files changed, 510 insertions, 0 deletions
diff --git a/js/demo/Ice/latency/.gitignore b/js/demo/Ice/latency/.gitignore new file mode 100644 index 00000000000..916894afcf6 --- /dev/null +++ b/js/demo/Ice/latency/.gitignore @@ -0,0 +1 @@ +Latency.js diff --git a/js/demo/Ice/latency/Client.js b/js/demo/Ice/latency/Client.js new file mode 100644 index 00000000000..b0a2034e40e --- /dev/null +++ b/js/demo/Ice/latency/Client.js @@ -0,0 +1,91 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +(function(){ + +require("Ice"); +require("./Latency"); + +var communicator; + +// +// Asynchronous loop, each call to the given function returns a +// promise that when fulfilled runs the next iteration. +// +function loop(fn, repetitions) +{ + var i = 0; + var next = function() + { + if(i++ < repetitions) + { + return fn.call().then(next); + } + }; + return next(); +} + +Ice.Promise.try( + function() + { + // + // Initialize the communicator and create a proxy to the + // ping object. + // + communicator = Ice.initialize(); + var repetitions = 10000; + var proxy = communicator.stringToProxy("ping:default -p 10000"); + + // + // Down-cast the proxy to the Demo.Ping interface. + // + return Demo.PingPrx.checkedCast(proxy).then( + function(obj) + { + console.log("pinging server " + repetitions + " times (this may take a while)"); + start = new Date().getTime(); + return loop( + function() + { + return obj.ice_ping(); + }, + repetitions + ).then( + function() + { + // + // Write the results. + // + total = new Date().getTime() - start; + console.log("time for " + repetitions + " pings: " + total + "ms"); + console.log("time per ping: " + (total / repetitions) + "ms"); + }); + }); + } +).finally( + function() + { + // + // Destroy the communicator if required. + // + if(communicator) + { + return communicator.destroy(); + } + } +).exception( + function(ex) + { + // + // Handle any exceptions above. + // + console.log(ex.toString()); + process.exit(1); + }); +}()); diff --git a/js/demo/Ice/latency/Latency.ice b/js/demo/Ice/latency/Latency.ice new file mode 100644 index 00000000000..2391b2667aa --- /dev/null +++ b/js/demo/Ice/latency/Latency.ice @@ -0,0 +1,19 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +module Demo +{ + +class Ping +{ +}; + +}; diff --git a/js/demo/Ice/latency/Makefile b/js/demo/Ice/latency/Makefile new file mode 100644 index 00000000000..5b712f95b52 --- /dev/null +++ b/js/demo/Ice/latency/Makefile @@ -0,0 +1,16 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +TARGETS = Latency.js + +include $(top_srcdir)/config/Make.rules.js + +SLICE2JSFLAGS := $(SLICE2JSFLAGS) -I$(slicedir) diff --git a/js/demo/Ice/latency/Makefile.mak b/js/demo/Ice/latency/Makefile.mak new file mode 100644 index 00000000000..ded034bf05d --- /dev/null +++ b/js/demo/Ice/latency/Makefile.mak @@ -0,0 +1,16 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ..\..\.. + +TARGETS = Latency.js + +!include $(top_srcdir)\config\Make.rules.mak.js + +SLICE2JSFLAGS = $(SLICE2JSFLAGS) -I"$(slicedir)" diff --git a/js/demo/Ice/latency/README b/js/demo/Ice/latency/README new file mode 100644 index 00000000000..8f6f193a0b1 --- /dev/null +++ b/js/demo/Ice/latency/README @@ -0,0 +1,21 @@ +A simple latency test that measures the basic call dispatch delay of +Ice. + +To run the demo, first you need to start the Ice latency server. This +distribution includes server implementations in Python and C++, and +each one has its own README file with instructions for starting the +server. Please refer to the Python or C++ README in the appropriate +demo subdirectory for more information. + +Note: + + * To use the Python server you'll need a Python installation that is + compatible with the Ice for Python module included in Ice 3.5.1. + + * To use the C++ server you'll need a C++ compiler compatible with + the Ice 3.5.1 C++ distribution. + +After starting the server, open a separate window and start the +client: + +$ node Client.js diff --git a/js/demo/Ice/latency/browser/Client.js b/js/demo/Ice/latency/browser/Client.js new file mode 100644 index 00000000000..3a86f26c7ed --- /dev/null +++ b/js/demo/Ice/latency/browser/Client.js @@ -0,0 +1,161 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +(function(){ + +var Promise = Ice.Promise; + +// +// Initialize the communicator +// +var communicator = Ice.initialize(); + +// +// Run the latency test. +// +function run() +{ + // + // Create a proxy to the ping object. + // + var hostname = document.location.hostname || "127.0.0.1"; + var secure = document.location.protocol.indexOf("https") != -1; + var ref = secure ? + "ping:wss -h " + hostname + " -p 9090 -r /demowss" : + "ping:ws -h " + hostname + " -p 8080 -r /demows"; + var proxy = communicator.stringToProxy(ref); + + var repetitions = 1000; + + // + // Down-cast the proxy to the Demo.Ping interface. + // + return Demo.PingPrx.checkedCast(proxy).then( + function(obj) + { + writeLine("pinging server " + repetitions + " times (this may take a while)"); + start = new Date().getTime(); + return loop( + function() + { + return obj.ice_ping(); + }, + repetitions + ).then( + function() + { + // + // Write the results. + // + total = new Date().getTime() - start; + writeLine("time for " + repetitions + " pings: " + total + "ms"); + writeLine("time per ping: " + (total / repetitions) + "ms"); + setState(State.Idle); + }); + }); +} + +// +// Run button event handler. +// +$("#run").click( + function() + { + // + // Run the latency loop if not already running. + // + if(state !== State.Running) + { + setState(State.Running); + + Ice.Promise.try( + function() + { + return run(); + } + ).exception( + function(ex) + { + $("#output").val(ex.toString()); + } + ).finally( + function() + { + setState(State.Idle); + } + ); + } + return false; + }); + +// +// Asynchronous loop: each call to the given function returns a +// promise that when fulfilled runs the next iteration. +// +function loop(fn, repetitions) +{ + var i = 0; + var next = function() + { + if(i++ < repetitions) + { + return fn.call().then(next); + } + }; + return next(); +} + +// +// Helper function to write the output. +// +function writeLine(msg) +{ + $("#output").val($("#output").val() + msg + "\n"); + $("#output").scrollTop($("#output").get(0).scrollHeight); +} + +// +// Handle the client state. +// +var State = { + Idle:0, + Running: 1 +}; + +var state; + +function setState(s, ex) +{ + if(s != state) + { + switch(s) + { + case State.Running: + { + $("#output").val(""); + $("#run").addClass("disabled"); + $("#progress").show(); + $("body").addClass("waiting"); + break; + } + case State.Idle: + { + $("#run").removeClass("disabled"); + $("#progress").hide(); + $("body").removeClass("waiting"); + break; + } + } + state = s; + } +} + +setState(State.Idle); + +}()); diff --git a/js/demo/Ice/latency/build.js b/js/demo/Ice/latency/build.js new file mode 100644 index 00000000000..4ef18bb7834 --- /dev/null +++ b/js/demo/Ice/latency/build.js @@ -0,0 +1,10 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +require ("../../../config/build").build(__dirname, ["Latency.ice"]); diff --git a/js/demo/Ice/latency/expect.py b/js/demo/Ice/latency/expect.py new file mode 100755 index 00000000000..3e0c8d19d2f --- /dev/null +++ b/js/demo/Ice/latency/expect.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import sys, os, signal + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "demoscript")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(path[0]) + +from demoscript import Util + +server = Util.spawn('./server --Ice.PrintAdapterReady', Util.getMirrorDir("cpp"), mapping="cpp") +server.expect('.* ready') + +sys.stdout.write("testing ping... ") +sys.stdout.flush() +client = Util.spawn('node Client.js') +client.waitTestSuccess(timeout=100) +print("ok") + +server.kill(signal.SIGINT) +server.waitTestSuccess() + +print(client.before) diff --git a/js/demo/Ice/latency/index.html b/js/demo/Ice/latency/index.html new file mode 100644 index 00000000000..7d5fba1c27b --- /dev/null +++ b/js/demo/Ice/latency/index.html @@ -0,0 +1,139 @@ +<!doctype html> +<html class="no-js" lang="en"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Latency Demo | Ice for JavaScript</title> + <!-- Bundle with all the stylesheets used to build the user interface, + see assets/Makefile in your distribution for details --> + <link rel="stylesheet" type="text/css" href="../../../assets/common.css" /> + <link rel="icon" type="image/x-icon" href="../../../assets/favicon.ico"> + </head> + <body> + <!-- Header section that contains title and navigation bar --> + <section id="header"> + <nav class="top-bar" data-topbar> + <ul class="title-area"> + <li class="name"> + <h1><a href="../../../index.html">Ice for JavaScript</a></h1> + </li> + <li class="toggle-topbar menu-icon"><a href="#">Menu</a></li> + </ul> + <section class="top-bar-section"> + <!-- Right Nav Section --> + <ul class="right"> + <li class="divider"></li> + <li><a href="#" id="viewReadme">Readme</a></li> + <li><a href="#" id="viewSource">Source</a></li> + </ul> + </section> + </nav> + <ul class="breadcrumbs"> + <li><a href="../../../index.html">Ice</a></li> + <li><a href="../../index.html">Demos</a></li> + <li class="current"><a href="#">Latency</a></li> + </ul> + </section> + <!-- Main section that contains the user interface --> + <section role="main" id="body"> + <div class="row"> + <div class="large-12 medium-12 columns"> + <form> + <a href="#" class="button small" id="run">Run</a> + <div class="row"> + <div class="small-12 columns"> + <textarea id="output" class="disabled" readonly></textarea> + </div> + </div> + <div id="progress" class="row hide"> + <div class="small-12 columns left"> + <div class="inline left icon"></div> + <div class="text">Running...</div> + </div> + </div> + </form> + </div> + </div> + </section> + <!-- Modal dialog to show the client README --> + <div id="readme-modal" class="reveal-modal medium" data-reveal> + <h4>Latency Demo Readme</h4> + <hr/> + <p>A simple latency test that measures the basic call dispatch delay of + Ice.</p> + + <p>To run the demo, first you need to start the Ice latency server. This + distribution includes server implementations in Python and C++, and + each one has its own README file with instructions for starting the + server. Please refer to the Python or C++ README in the appropriate + demo subdirectory for more information. + </p> + + <div class="panel callout radius"> + <ul> + <li>To use the Python server you'll need a Python installation that is + compatible with the Ice for Python module included in Ice 3.5.1.</li> + + <li>To use the C++ server you'll need a C++ compiler compatible with your + Ice for JavaScript distribution.</li> + </ul> + </div> + + <p>Then you can use the <strong>"Run"</strong> button to run this client.</p> + + <div class="panel callout radius"> + <p>The client is configured to use WSS secure endpoints when the page + is loaded over HTTPS and WS unsecure endpoints when loaded over HTTP.</p> + </div> + <a class="close-reveal-modal">×</a> + </div> + <!-- Modal dialog to show the client source code --> + <div id="source-modal" class="reveal-modal" data-reveal> + <a class="close-reveal-modal">×</a> + <dl class="tabs" data-tab> + <dt></dt> + <dd class="active"><a href="#panel2-1">Slice</a></dd> + <dd><a href="#panel2-2">JavaScript</a></dd> + <dd><a href="#panel2-3">HTML</a></dd> + </dl> + <div class="tabs-content"> + <div class="content active" id="panel2-1"> + <h6>File: Ice/latency/Latency.ice</h6> + <pre class="source language-c" data-code="Latency.ice"></pre> + </div> + <div class="content" id="panel2-2"> + <h6>File: Ice/latency/browser/Client.js</h6> + <pre class="source" data-code="browser/Client.js"></pre> + </div> + <div class="content" id="panel2-3"> + <h6>File: Ice/latency/index.html</h6> + <pre class="source" data-code="index.html"></pre> + </div> + </div> + </div> + <!-- Footer section --> + <section id="footer"> + <div class="logo"> + <h4><strong>ZeroC</strong></h4> + </div> + <div class="copyright"> + <h6>© 2014 ZeroC, Inc. All rights reserved.</h6> + </div> + </section> + <!-- Bundle with all the scripts used to build the user interface, + see assets/Makefile in your distribution for details --> + <script type="text/javascript" src="../../../assets/common.min.js"></script> + <!-- Ice.js (Ice run-time library) --> + <script type="text/javascript" src="../../../lib/Ice.js"></script> + <!-- Latency.js (Demo generated code) --> + <script type="text/javascript" src="Latency.js"></script> + <!-- browser/Client.js (Latency Demo Application) --> + <script type="text/javascript" src="browser/Client.js"></script> + <script type="text/javascript"> + if(["http:", "https:"].indexOf(document.location.protocol) !== -1) + { + checkGenerated(["Latency.js"]); + } + </script> + </body> +</html> |