📜 ⬆️ ⬇️

Caucho Resin - Java / PHP Application Server

For Java applications, I mean, web applications, there are already a sufficient number of servers that have long been developed and long ago reached a level sufficient to apply them in the most complex and demanding cases. I think everyone knows Apache Tomcat and Jetty - the most famous servers from the list of open source development. But to this list you need to add now also Caucho Resin . In a number of tests, its Pro version is superior in performance to Tomcat 6, while possessing a number of out-of-box features that are not found in other servers or they are implemented using third-party tools.

And so, Resin is a high-performance HTTP and application server for Java / PHP applications, with the ability to scale and cluster in the initial configuration. By the way, this is exactly the difference between the regular, open-source version and Pro. In this version there are functions for automatic detection of stopped or hung sessions and server restart, as well as means of monitoring the state of the JVM and memory consumption. Clustering allows you to distribute the load across multiple servers, while the sessions will be tied to a specific server and migrate in the background when the node serving it crashes. It’s worth it as a separate talk, perhaps in a separate article - I’m going to study closely this server and its capabilities, and I’ll publish the result in the form of articles.


Resin-a feature in terms of performance is the use of native code for the main server functionality, in particular, for working with sockets and file system. The server runs on Linux and Win32 systems, and each has its own code, which allows you to use all the features of the server. Although most of the server is written in Java and runs on top of the JVM.
')
SSL support is mandatory for a modern server, so support for the OpenSSL library is not even worth considering - this is so clear. But the built-in caching system favorably distinguishes Resin from other servers that need additional components or third-party applications. The server can cache frequently requested pages in memory or use a cache for static data like images. Part of the cache is used to cache internal objects, avoiding the load on the database. Of course, for serious applications it is necessary to use powerful independent solutions, such as the EHCache described by us , but at the initial stage using Resin we will immediately get all the necessary features that we can expand in the future.

There is another, truly unique opportunity built in the server (as for such servers) - a built-in connection pool for accessing databases, supporting any JDBC drivers using load balancing (using the round robin algorithm) and a disaster recovery mechanism. Although this does not negate the use of third-party, more powerful tools for clustering databases, but immediately from the box will provide more than ample opportunities for any application.

Like Jetty, Resin supports Comet technology (or protocol) for Server-Push implementation. This is especially important for the implementation of various modern web 2.0 services, for example, web chats and other communication applications. In the assets of Caucho, a development company, there is also a Hessian project - a binary format and protocol for fast data transfer between web services components or applications, an analogue of XML, SOAP or JSON, and if you use the corresponding library, you can use this faster protocol ( described in more detail here ).

And so, about architecture. The application server itself can work on Win32, MacOS, Sun Solaris and Linux platforms (on FreeBSD, there were or were previously problems with the JDK). The package includes its own HTTP server, however, it is provided to work with an external web server, in particular, Apache or IIS, as well as with any server via CGI. I believe that paired with Apache or, even better, with nginx is the most preferred configuration for loaded projects, these servers will take on themselves the processing of static files and even the initial load balancing (nginx), and requests that require processing are transferred to Resin . It works by default on port 8080, but this, of course, is configured separately, if there are no other servers, you can use the built-in one, transferring it to the usual 80 port.

Resin itself is performed on top of the Java Virtual Machine, and therein lies its strength (let's talk about this a little later). All the power of java technologies and the JDBC interface are used to communicate with databases. That's all. It is worth mentioning the supported technologies for Java applications. I’m not a strong expert in the Java world, so I’ll just list: WebBeans (JSR-299), EJB 3.0 , Java Server Page (JSP 2.1), Java Standard Template Library (JSTL 1.0.1), Servlet 2.5, Java Persistence Architecture ( JPA), Messaging API 1.1, Transaction 1.0.1b, JNI and others. All this allows you to fully use all the developments and third-party applications already written and working in other servers.

And now, lastly, the most important and interesting (for me and, I hope, for you) - actually, because of what this article, or even a series of articles, was started. After all, the Java application server itself is not the most innovative and interesting, right? Even with such opportunities.

At the beginning of the article I mentioned that Resin is a server for Java / PHP applications. PHP? That's right - in the assets of Caucho there is a FULL port of PHP and the main Java libraries - Quercus ! And not just a port, but a full-featured Java-based PHP application server. And it is part of Resin, although it is also available as an independent module. Quercus is written entirely in Java and contains not only the basic functionality of PHP-core, but also a number of popular extensions - PDO, JSON, PDF, APC, iconv, GD, gettext. This allows you to run most of the popular PHP projects, including CMS-systems without any alterations (only replacing the parameters of access to the database). The tests stated that the popular Drupal CMS system running on the Resin server shows up to 4-fold increase in performance.

But the most important thing is not that. And the fact that a PHP application running in such an environment automatically receives everything, I repeat, all the features of the Java platform, and the same Resin server as described above. Remember about clustering, dynamic migration of sessions between cluster nodes, pool of connections to the database (this is very, very important, I already raised this topic in my first study, and only now I found a way to implement it), as well as access to all Java - applications and system components. At the same time, you write your usual code in the familiar and familiar PHP language. Or even do not write anything, just configure Resin and run your project on top of it, immediately greatly expanding its capabilities and performance. But for Resin itself, all the tools are available for managing and scaling Java applications that are not so few in the market, many have been tested and are used in the most large-scale projects.

By the way, do you think this is such a unique technology that I dug up exclusively to explore and abandon? And how do you like the fact that one of the largest sites of the Runet, the social network Odnoklassniki.ru works exactly on the Resin application server (2.1.16)? This indicates the maturity and relevance of the technology, both for the traditional Java market and the PHP market. Some features are present in the Zend Platform , for example, clustering and session transfer, performance monitoring and load balancing, but Resin also provides much more, and at a cost it is much more attractive. Compare - 500 USD for a processor license for Resin and from 999 USD for the Zend Platform. At the same time, it’s curious that Platform has a Java Bridge component that is responsible for integrating and interacting with Java applications and web services. Apparently, even the main PHP company and the developer of commercial products for and for PHP understands and wants to use the power and breadth of opportunities from the Java world, while not forcing to retrain and change the PHP language of developers.

That's all, a brief introduction to the topic is over, I will begin a thorough study of the possibilities of Resin-a and some Java in general, so in the future there will be more than one article on this topic, the truth is more specific and practical. First of all, I will try to set up a pool of connections to the database and maybe try to run a PHP application that will use database access through some other access stack, for example, lbpool or Continuent Tungsten . I'll try to consider also independent tools for clustering Java applications, for example, Terracotta .

PS Original article written for my personal blog: Alpha-Beta-Release Blog

Source: https://habr.com/ru/post/39037/


All Articles