Announcement Announcement Module
No announcement yet.
newbie: Spring, J2EE and clustering Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • newbie: Spring, J2EE and clustering


    I have read a course at the university about Distributed system so I have a basic understanding about distributed system and algorithms. But now I want to knowhow such a system is implemented using J2EE, and specifilly using the spring framework and Hibernate.

    My idea of a distributed system (a server cluster) is that you have a number of serversand on each server you have a database (a replica) and a server application (in this case that would be the spring aplication) the frontend (i.e. client application) connects to one of the servers, which one is done by some load balancing (could be done in hardware i think).
    The client interacts with the server apllication and the server application updates the databse, this would lead to that all other database replicas also are updated, so that when another clientconnects to and inteacts with another server apllication it has the latest information to work with.

    I have tired to understand how this works in J2EE, spring framework with Hibernate, and _I have found references to JNDIor something like that but still I donthave a clear picture of how this is done with J2EE, or the spring framework. Could anyone care to enlighen me?

    And also where can I find information on how to have a spring application avalible on the net but not throught the http protocol but rather a custom made protocol over TCP/IP?



  • #2
    A distributed system and a server cluster are different things in my book. Also, when talking about clustering, it's often useful to specify whether you're doing it to achieve scale-out and/or failover.

    Spring also doesn't specifically provide any help in setting up a server cluster.

    To set up a cluster you can do something like:

    1. Use MySql and run a master/slave setup.

    2. Use JGroups to deliver a clustered cache. e.g. the JBoss TreeCache distributed cache plugin for Hibernate. This is so you can run a distributed 2nd level cache which delivers a massive speed boost for most business systems. If you were using entity beans, then JBoss uses JGroups by default to deliver distributed caching.

    3. Use Apache and mod_jk2 as a front end to the cluster. You can then choose to use sticky sessions to avoid having to replicate sessions or whatever depending on your requirements.

    When a request comes in, Apache load balances it to any box running your Spring app.

    If it's a write request (or a read request that needs a guarantee that it's reading the absolute latest data -- depending on how frequently slaves update) then you'd get your DAO layer to access the box that your master DB is on.

    Otherwise, you can read from any of the slave servers.

    You don't have to do both 1. and 2. above, doing only one of those options will deliver some level of scale-out.

    Also, in my experience, you're better off replicating all the components on each box in the cluster, rather than having a "web server", and an "application server", and a "database server", etc. This just generates unnecessary network calls.

    If you want full write ability on any node, you need to run a MySql Cluster, or sell your house and buy Oracle. I believe (?) Postgresql are also looking at delivering a multi-master solution at some stage.

    We use MySql on one production system, with InnoDB on the master, and MyISAM on the slaves. Reports and quartz jobs run against the slaves to keep load off the master.

    I'd be interested also to hear what other people are doing.


    • #3

      I have a fairly large application on Werblogic 8.1 with Oracle 10g. This application is developed using Spring and Hibernate. The application is 2-tier (co-located). Can I use the clustering support provided by the app server for providing fail-over and scalability? Do I need to do anything specifc on my Spring configs to ensure that this will work as expected?

      We have minimum dependency on Weblogic/Oracle and may need to migrate to JBoss/MySQL in the future.



      • #4
        Yes, you'd need to enable a clustered Hibernate cache or avoid using caching. i.e. ehcache won't work in a clustered environment.


        • #5
          I seem to remember that ehcahe is distributed currently

          Ehcache uses RMI, based on custom socket options for delivery in its default implementation.
          A JGroups implementation is planned for ehcache-1.2.1.


          • #6
            Seems like it is distributed now, and also supports cache invalidation (as opposed to copy).

            Can't see anything about it being transactional. Anyone know if it is?


            • #7
              Thanks Mathews. I am using OSCache currently for read-only second level caching at Hibernate. Not planning to have a transactional cache as of now. My concern is about the behaviour of Spring beans, which are singletons by default, in a clustered environment.

              As a matter of policy, we dont maintain any ojbect in the HttpSession. In this case, I am afraid that the Spring ApplicationContext will be specific to each nodes in the cluster and thus the beans may have inconsistent data across nodes at a given point of time.