HPC Server 2008 R2 SDK SP1 contains sample code that demonstrates the usage of Java on the client side. The framework enables a Java-to-Java communication within HPC Server 2008 R2 SP1. It enables to send Java objects on the client side and process them on the service side within stateful Java processes. The Project Sources are published on MSDN.
The HPC Java Bridge plugs into the existíng HPC SOA architecture. We can identify at least 3 different tiers that are related to the bridge:
Please follow these steps to configure the WCF Service.
<microsoft.Hpc.Session.ServiceRegistration> <service assembly="\\myshare\HPCJavaBridge\HPCJavaBridge\bin\Debug\HPCJavaBridge.dll" contract="HPCJavaBridge.IHPCJavaBridge" type="HPCJavaBridge.HPCJavaBridge" includeExceptionDetailInFaults="true" maxConcurrentCalls="0" serviceInitializationTimeout="60000" stdError="" maxMessageSize="2147483647"> <environmentVariables> <add name="ChunkFolder" value="\\myshare\Chunks\"/> <add name="JavaExe" value="\\myshare\jdk1.6.0_21\jre\bin\java"/> <add name="JavaArgs" value="-Xms64m -Xmx1024m -cp \\myshare\workspace\HPCJavaService\bin\. hpc.test.PingPongSampleService"/> <add name="PortRangeStart" value="42000"/> <add name="PortRangeEnd" value="49000"/> </environmentVariables> </service></microsoft.Hpc.Session.ServiceRegistration>
The Java client side requires the CXF libraries as well as the generated Session and HPC Java Bridge service API. Once added to the classpath create custom Java client code as displayed below. It allows compression, serialization and distribution of any serializable Java object through the JavaClientSingleton class.
Let's have a look at the following SimplePingPongClient sample:
package hpc.test;import com.microsoft.hpc.scheduler.session.modified.AsyncMessageReceiver;import hpc.clientSide.JavaClientSingleton;import hpc.sharedObjects.PingPong;public class SimplePingPongClient { public static void main(String[] args) throws Exception { JavaClientSingleton jc = JavaClientSingleton.getInstance(); jc.setHeadNode("head"); jc.setDomainName("hpc"); jc.setUserName("alibaba"); jc.setPassword("al!b!ba"); jc.setServiceName("HPCJavaBridge"); jc.setJobTemplateName("hpcjavabridge"); jc.setMinUnits(2); jc.setUnitType(0); jc.setMaxUnits(4); jc.setReuseSession(true); jc.setUseDurableSessions(false); AsyncMessageReceiver amr = new AsyncMessageReceiver() { @Override public void OnMessageReceive(Object Message) { System.out.println("[received]"); if(Message instanceof PingPong) { PingPong pp = (PingPong) Message; System.out.println("ping/pong from host: " + pp.getHostName()); } } }; jc.distributeJobs(new Object[] {new PingPong(), "I'm a string job", new Long(123)}, 4, amr, true); }}
distributes the job objects. Parameters are:
Warms up a session by sending simple ping pong messages to the cluster. This will create a session and initialize the service instances which consumes most of the time. By calling this method at the beginning of all user interactions the minimum send/response time is achieved. Parameters are:
The published service API includes a ping pong test class. Any Java service that will be implemented to interchange with the proposed HPC Java Bridge framework will need to extend the JavaProcessStarterImpl class. Place your custom code with these 3 methods:
Make sure to add a main-method to your starting class. Call the Publish-method to startup the Java process to start the communication with the HPC Java Bridge framework. The WebService attribute values need to be identical for every custom service. Make sure to copy and past them from the PingPongSampleService class.
package hpc.test; import hpc.serviceSide.fileLessIntegration.JavaProcessStarterImpl;import java.net.InetAddress;import java.util.Date;import javax.jws.WebService; @WebService( endpointInterface = "hpc.serviceSide.fileLessIntegration.JavaProcessStarter", name="JavaProcessStarter", serviceName="JPSService", targetNamespace=http://hpcjavasoabridge.org/soa2java) public class PingPongSampleService extends JavaProcessStarterImpl { @Override protected void initializeInstance() { System.out.println("local init"); } @Override protected void shutdownInstance() throws Exception { System.out.println("good-bye!"); } @Override protected Object processInstance(Object JavaObject) throws Exception { System.out.println("processing object"); if(JavaObject instanceof Long) return "hello long"; else return new Date(); } public static void main(String[] args) throws Exception { PingPongSampleService PPSS = new PingPongSampleService(); PPSS.Publish(args); }}
The performance tests are ongoing. First results with sending, compressing, receiving and decompressing simple PingPong Java objects within a "warm" session show very, very fast results.