分散関数呼び出し
Posted feedbacks - Java
RMIの実装です(Java 5ではrmic不要になっているのですね)。 一万回呼び出しにかかった時間:4782 ms ・サーバとクライアントのCPU・メモリ:PowerPC G4 1.67 GHz・メモリ 1GB ・同一サーバ内での実行か別サーバでの実行か:同一サーバ内 ・言語のバージョン:Java HotSpot(TM) Client VM build 1.5.0_07-87 ・ミドルウェアを使用している場合,その名前とバージョン:使用していない
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 共通のインタフェース(Price.java)
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Price extends Remote {
String priceString(int price, int discunt) throws RemoteException;
}
サーバ側実装(Server.java)
import java.rmi.registry.*;
import java.rmi.server.*;
public class Server implements Price {
public String priceString(int price, int discount) {
return String.format("販売価格 %,d円(定価 %,d円から %d%%引き)",
(int)(double)price * (100 - discount) / 100, price, discount);
}
public static void main(String[] args) throws Exception {
Server obj = new Server();
Price stub = (Price) UnicastRemoteObject.exportObject(obj, 0);
Registry reg = LocateRegistry.getRegistry();
reg.bind("Price", stub);
}
}
クライアント側実装(Client.java)
import java.rmi.registry.*;
public class Client {
public static void main(String[] args) throws Exception {
String host = (args.length < 1)? null : args[0];
Registry reg = LocateRegistry.getRegistry(host);
Price stub = (Price) reg.lookup("Price");
long now = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
stub.priceString(1000, 20);
}
System.out.printf("%d ms%n", System.currentTimeMillis() - now);
}
}
|
JAX-WSによる実装です。SOAP1.2に準拠しているとの記述がありますので、タグはSOAPとします(他言語との相互接続は確認していません)。
一万回呼び出しにかかった時間:73255 ms
・サーバとクライアントのCPU・メモリ:Efficeon 998 MHz・メモリ 232MB
・同一サーバ内での実行か別サーバでの実行か:同一サーバ内
・言語のバージョン:Java HotSpot(TM) Client VM build 1.6.0_02-b06
・ミドルウェアを使用している場合,その名前とバージョン:使用していない
一万回呼び出しにかかった時間:73255 ms
・サーバとクライアントのCPU・メモリ:Efficeon 998 MHz・メモリ 232MB
・同一サーバ内での実行か別サーバでの実行か:同一サーバ内
・言語のバージョン:Java HotSpot(TM) Client VM build 1.6.0_02-b06
・ミドルウェアを使用している場合,その名前とバージョン:使用していない
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | サーバ側実装
package org.example.jaxws;
import javax.jws.WebService;
@WebService
public class Sample {
public String priceString(int price, int discount) {
return String.format("販売価格 %,d円 (定価 %,d円から %d%%引き)",
price * (100 - discount) / 100, price, discount);
}
}
サーバメイン
package org.example.jaxws;
import javax.xml.ws.Endpoint;
public class SampleMain {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/Sample", new Sample());
}
}
クライアント側実装
package org.example.jaxws;
public class Client {
public static void main(String[] args) {
SampleService service = new SampleService();
Sample port = service.getSamplePort();
long start = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
port.priceString(2000, 20);
}
System.out.printf("%d ms%n", System.currentTimeMillis() - start);
}
}
|


沢渡 みかげ
#3401()
Rating0/0=0.00
[ reply ]