VM Performance: Calling javascript functions from Applet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SPG

    VM Performance: Calling javascript functions from Applet

    Hi,

    We have an applet that has to support the SUN VMs as well as the MS VM.
    The applet receives updates from a server (via tcp or http) and wraps them
    up as objects and passes them using the JSObject scripting context to a
    javascript function.

    This function takes the object and reads the properties and updates a
    screen.

    All seems simple stuff. The problem is that the MS JVM runs like a rocket,
    but the sun vm seems to max out our processor and also takes ages to process
    anything.

    I have tried logging from the console using debug level 5, and it shows a
    lot of back and forth between the applet and the javascript when accessing
    methods on the object passed.

    Seeing that as a possible problem, I now pass a delimited string to the
    front end, and then convert that into an update message purely in javascript
    so there is only one hit to the applet per message.

    I am still seeing a massive difference between the sun and ms VMs.

    Has anyone ever come across this, and is there anything I can do to help
    flatten out this performance?

    Steve


  • SPG

    #2
    Re: VM Performance: Calling javascript functions from Applet

    Hi,

    OK, Below is a quick sample.. A bit nasty code-wise but sort of highlights
    what we are doing in a very rough way.
    I have two message pumps to simulate multiple threads updating prices...

    We find the MS VM to be far more performant than the SUN version...
    It would be really great if we could at least find out why the sun vm is so
    poor at handling this, so we can start rectifying our mistakes!

    Steve

    <snip code="applet code">
    import java.awt.*;
    import java.awt.event. *;
    import java.applet.*;
    import netscape.javasc ript.*;
    import java.util.*;

    public class LoadTest
    extends Applet {

    private String jsFunction = "handleUpda te";
    private JSObject win;
    MessagePump pump1;
    MessagePump pump2;

    //Construct the applet
    public LoadTest() {
    }

    //Initialize the applet
    public void init() {
    try {
    win = JSObject.getWin dow(this);
    pump1 = new MessagePump((in t)(Math.random( )*500)+300);
    pump1.start();
    pump2 = new MessagePump((in t)(Math.random( )*500)+300);
    pump2.start();
    }
    catch (Exception e) {
    e.printStackTra ce();
    }
    }

    public void destroy(){
    pump1.interrupt ();
    pump2.interrupt ();
    super.destroy() ;

    }

    private void sendUpdate(fina l Message m){
    try{
    final Object[] params = new Object[]{m};
    win.call(jsFunc tion, params);
    }catch(Exceptio n err){}
    }

    private class MessagePump extends Thread{
    private long _wait;
    public MessagePump(lon g wait){
    _wait = wait;
    }
    public void run(){
    while(! interrupted()){
    for(int i=0; i < 20; i++){
    Message m = new Message("" + (i+1), "" +
    (Math.random()* 100),"" + (Math.random()* 100),new Date());
    sendUpdate(m);
    }
    try {
    Thread.sleep(_w ait);
    }
    catch (InterruptedExc eption ex) {
    }
    }
    }
    }

    }
    </snip>
    <html>
    <head>
    <title>
    HTML Test Page
    </title>
    <SCRIPT language="JavaS cript">
    function handleUpdate(ms g)
    {
    try{
    var id = msg.getID();
    var date = msg.getDate();
    var bid = msg.getBid();
    var ask = msg.getAsk();

    var table = document.getEle mentById("Price s");
    var row = table.rows[id];

    row.cells[0].firstChild.nod eValue = id;
    row.cells[1].firstChild.nod eValue = date;
    row.cells[2].firstChild.nod eValue = bid;
    row.cells[3].firstChild.nod eValue = ask;
    }catch(e)
    {
    alert(e);
    }

    }
    </SCRIPT>
    </head>
    <body>
    <h1>Using Direct Access</h1>
    <table border=1 id="Prices">
    <thead id="Title">
    <tr>
    <th>ID</th>
    <th>Date</th>
    <th>Bid</th>
    <th>Ask</th>
    </tr>
    </thead>
    <tr id="1">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="2">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="3">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="4">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="5">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="6">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="7">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="8">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="9">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="10">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="11">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="12">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="13">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="14">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="15">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="16">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="17">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="18">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="19">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    <tr id="20">
    <td id="ID">&nbsp; </td>
    <td id="DATE">&nbsp ;</td>
    <td id="BID">&nbsp; </td>
    <td id="ASK">&nbsp; </td>
    </tr>
    </table>
    <applet
    codebase = "."
    code = "LoadTest.class "
    name = "TestApplet "
    width = "0"
    height = "0"
    hspace = "0"
    vspace = "0"
    align = "middle"
    MAYSCRIPT[color=blue]
    >[/color]
    </applet>
    </body>
    </html>


    <snip code="html">


    </snip>



    Comment

    Working...