Docstoc

Quercus and Hessian

Document Sample
Quercus and Hessian Powered By Docstoc
					Quercus and Hessian

       Scott Ferguson
Co-Founder and Chief Architect
   Caucho Technology, Inc.
      www.caucho.com
                   Quercus
●   Caucho's cleanroom implementation of PHP in
    Java
●   PHP 4 language features complete
●   PHP 5 features mostly complete
                  Library status
●   Core libraries (string, regexp, array, mysql, etc)
    complete
●   Implementation of others progresses
●   http://wiki.caucho.com/PHP_implemenation_sta
    tus
         Applications on Quercus
●   Mediawiki (wikipedia)
●   Drupal – content management
●   Mantis – bug tracking
                 Performance
●   Using default mediawiki homepage
●   3x faster with straight mod_php
●   80% faster than eaccelerator for mediawiki
●   Same speed as eaccelerator for Drupal
●   Your mileage may vary
             Quercus use cases
●   PHP applications wanting Java performance,
    stability, security, scalability
●   Java sites wanting PHP web-apps, e.g. wiki,
    blogs.
●   Java applications using PHP as presentation
    layer
                 Performance
●   PHP to bytecode compilation
●   Multithreading
●   Connection pooling
●   Caching
                       Security
●   Avoid buffer overruns
       Not just PHP implementation
       Also any modules with C code
●   Libraries such as JavaMail
●   Move database config out of code
                     Stability
●   Avoid segvs in library code
●   Memory management and GC
                     Java tools
●   Can use Java IDEs with PHP
       Compiled modes
●   Profilers
●   Heap analyzers
●   JMX
PHP as presentation layer for Java
●   JSP
●   Velocity
●   Struts
●   JSF
            Presentation Models
1)index.php calling Java extension library
     Simpler, avoids complicated frameworks
2)javax.script from Java to PHP scripts
     If already have framework, use as extensions
                PHP advantages
●   Rapid prototyping
●   Dynamic typing
●   Complete language
●   Large set of libraries
●   Customization
                Java advantages
●   Maintenance (typing)
●   Performance (depending)
●   Threading
●   Services/Listeners
●   Caching
●   Testing (jUnit)
●   Patterns, packaging, .jar
            PHP Customization
●   Widely known language
●   Suitable for casual programmers
●   Templates, themes
●   See Drupal
●   Avoids learning new customization language
             PHP language features
●   arrays (ordered HashMap)
●   eval()
●   string interpolation and multiline strings
●   Libraries
                        array()
●   First-class support for ordered HashMap
    $foo = array('a'=>'data-a', 'b'=>'data-b');
    $foo['c'] = 'data-c';

●   Main PHP data structure
●   Large library support
●   Libraries can assume array as return type
               PDO – Database access

●   Returns associative list
    while ($row = $rs->fetch()) {
    }

●   Contrast with JDBC
                    Pros and Cons

●   + Reduce number of data structures a
    programmer needs to learn
●   + Libraries can use and return arrays, i.e.
    assumed types
●   + PHP can concentrate on array libraries and
    language features
●   - typing and maintenance.
●   - lack of typing self-documentation
●   i.e. PHP useful in some contexts
                        PHP strings

●   Interpolation (“$n objects”)
●   Multiline strings
●   Used for binary and character
     Simplifies APIs, e.g. Encrypt or file i/o
     But causes confusion for unicode
                       eval()

●   Evaluates a string as PHP code
●   Useful for frameworks and templates
●   Powerful and dangerous
                Weaknesses of PHP

●   Threading
●   Caching
●   Custom modules
●   Dynamic typing
               Bytecode Compilation

●   Quercus compiles PHP to .java
●   Javac compiles to .class
●   The JIT compiles to machine code
                 Example of PHP Compile

function foo()
{
    $a = “hello”;
    return hello_world($a);
}


public Value fun_foo(Env env)
  throws Throwable
{
    Value v_a = null;
    env.checkTimeout();
    v_a = quercus_value_1;
    return HelloModule.hello_world(env, v_a.toValue());
}
                 Quercus modules

●   “model 1”
●   Incoming requests to PHP layer
●   PHP calls Java application facade
           Module implementation example

public class MysqliModule extends AbstractQuercusModule {
  public static Mysqli mysqli_connect(Env env,
       @Optional(“localhost”) String host,
       @Optional String userName,
       @Optional String password)
  {
      return new Mysqli(env, host, userName, password);
  }
               Hello, world module
public class HelloModule extends AbstractQuercusModule {
  public static String hello_world(String msg)
    {
        return “hello, “ + msg;
    }
}
               .jar packaging
●   META-INF/service
●   com.caucho.quercus.QuercusModule
     example.HelloModule
●   Drop in .jar, get new API
                   Java APIs
●   e.g. JMS, JNDI, EJB
●   Exposing Java API vs facade
●   For application, e.g. Session beans, Java API
    probably best
●   For JMS, PHP-style facade better
●   Avoid housekeeping overhead
●   Simplify API
               example facades
$bean = jndi_lookup(“persistence/PersistenceUnit/test”)




$jms = new JmsQueue(“jms/test”);
$jms->send(“hello, world”)
              Application Facade
●   Application model written in Java
●   jUnit, etc. for Java model
●   Quercus facade for Java
●   PHP calls to facade or jndi_lookup
                   javax.script
●   Java API standard in JDK 1.6.
●   Lets applications call Quercus from Java
●   Use for PHP customization of frameworks
●   Use for presentation pages of JSF
●   Available in next release of Resin
                     Hessian
●   Compact, binary RPC protocol
●   Multilanguage support
●   Integrated with Spring
                  Languages
●   Java
●   .net C#
●   PHP
●   Ruby
●   Python
●   Objective C
                     History
●   Descended from XML-RPC
●   Reaction to complexity of SOAP
●   Burlap – XML based protocol
●   Hessian – binary protocol based on Burlap
          Changes from XML-RPC
●   Binary
●   Optional typing
●   Recursive structures
●   UTF-8 strings
●   8-bit binary
                Java Client API
String url = “http://www.caucho.com/hessian/test/basic”
HessianProxyFactory factory = new HessianProxyFactory();
Basic basic = (Basic) factory.create(Basic.class, url);
System.out.println(“hello(): “ + basic.hello());
               Java Server API
public class BasicService
    extends HessianServlet
    implements Basic {
    public String hello()
    {
        return “hello, world”;
    }
}
               Protocol examples
●   21
       I x00 x00 x00 x15

●   “Hello”
       S x00 x05 hello

●   array(“a”=>1)
       M S x00 x01 a I x00 x00 x00 x01
                       Principles
●   Self-describing
       No need for IDL
       Interoperate with scripting languages
●   KISS
       Minimize primitive types
       Minimize constructing types
●   Standardize encodings
       Utf-8
       8-bit binary
●   URLs
                        Types
   10 primitives, int, double, etc
   Ordered list
   Map
   Reference (recursive)
   Skip short, byte, unsigned, etc (.class)
   Utf-8 string (chunked)
   8-bit binary (chunked)
                     Chunked data
●   String, xml, binary
●   Lets sending code use fixed buffers
       b x10 x00 ... B x03 x43 ...
●   Suitable for large data
                          URLs
●   Use URLs as service addresses
       Familiar
       Complete
       Easy to publish and use
●   Avoid need for wsdl
●   Can identify object instances
       .../student?id=Harry+Potter
                  vs CORBA
●   Avoid IDL
●   Send types across (more data)
●   Use URL vs IOR
●   Standardize endian
●   Standardize string encoding
          vs SOAP

       Avoid XML overhead
        Avoid namespaces
        Full binary support
Avoid mixing protocol with validation
           Restrict typing
           Avoid WSDL
                 vs XML-RPC
●   Binary
●   Recursive structures
●   Optional typing
●   Remote objects
●   Method overloading
                        Conclusions
Questions
Future direction
Lokitech / Caucho Professional Services
Engineer position available at Caucho


Join us for drinks afterwards tonight!
-   Tequilaville, 2nd floor bar – 12 Vanderbilt Ave.

				
DOCUMENT INFO