VM Performance: Calling javascript functions from Applet

S

SPG

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
 
S

SPG

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.javascript.*;
import java.util.*;

public class LoadTest
extends Applet {

private String jsFunction = "handleUpdate";
private JSObject win;
MessagePump pump1;
MessagePump pump2;

//Construct the applet
public LoadTest() {
}

//Initialize the applet
public void init() {
try {
win = JSObject.getWindow(this);
pump1 = new MessagePump((int)(Math.random()*500)+300);
pump1.start();
pump2 = new MessagePump((int)(Math.random()*500)+300);
pump2.start();
}
catch (Exception e) {
e.printStackTrace();
}
}

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

}

private void sendUpdate(final Message m){
try{
final Object[] params = new Object[]{m};
win.call(jsFunction, params);
}catch(Exception err){}
}

private class MessagePump extends Thread{
private long _wait;
public MessagePump(long 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(_wait);
}
catch (InterruptedException ex) {
}
}
}
}

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

var table = document.getElementById("Prices");
var row = table.rows[id];

row.cells[0].firstChild.nodeValue = id;
row.cells[1].firstChild.nodeValue = date;
row.cells[2].firstChild.nodeValue = bid;
row.cells[3].firstChild.nodeValue = 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</applet>
</body>
</html>


<snip code="html">


</snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top