Showing posts with label sync4j. Show all posts
Showing posts with label sync4j. Show all posts

Sunday, February 6, 2011

How to host multiple instances of Sync4J server on one machine

There was one guy told me that he wanted to install multiple instances of sync4j in one Tomcat instance. He hoped that he can increase the performance of synchronization in this way. To increase performance of software, there are many aspects to work on. From the system architecture aspect, we can improve hardware system in vertical way and horizon way. I do not know if he go multi-CPU server and he can achieve better performance by increase number of instances on sync4j. It will be a big topic to discuss. Here, what I want to discuss is that it is impossible to install two sync4j server inside one Tomcat instance. The reasons are,

  1. Sync4j server uses the server.uri in Sync4j.properties as part of its authentication logic when it processing the syncMessage.
  2. Sync4j finds the path of configuration files based on a system properties called "SYNC4J_HOME". This is not a good design because this configuration property will be used JVM wide. Sync4j server, running in Tomcat, is a servlet. So, two sync4j instances will have to share same sync4j.properties. Therefore, I think Funambol should put all configuration related information under a Web App context only. But, they put the "SYNC4J_HOME" as a system property, which is JVM wide.


Based on the above two factors, I suggested him to install multiple tomcat and link each tomcat to a virtual host under Apache. But, please notice the second factor mentioned above, we will not run multiple tomcat instances on ONE virtual machine. So, we need run multiple binary copies of Tomcat. Then, we can set different Sync4j_Home for different Sync4j servers inside different Tomcat instance (different binary instance of Tomcat).

This installation configuration may cause challenge for sync module developers as they have to consider about plan of database instances. Will different sync4j module instances, having identical code base , share one database or different databases? Obviously, earlier designer think about this questions, better result they will have.

Note: the above analysis is based on sync4j server version 2.3 only. 

Friday, February 4, 2011

limitation of Sync4J to support sync from multiple subnet through proxy

I happened to had a look at AGPL again recently. AGPL is created to prevent people to host a modified open source project. Therefore, developer can not modify the software under AGPL project and deploy it on his own server as ASP. According to Funambol's site, it is said that user is not allowed to modify its source code even if the modification will be open source. I do not know if I understand it in correct way or not. As a programmer, I understood that open source projects need fund support to keep it to be alive.

But, this AGPL topic made me to recall one issue, i ran into when I worked on sync4j (old name of funambol). To describe the issue clearly, I made the following diagram,


As you can see, terminal one and terminal two sync with sync4j server from different sub net and through proxies respectively. Also, because DNS server in different sub net give the sync4j server different host name, terminal one and terminal two will sync to different host names, which are belong to one same physical server. In this case, the sync4j server can receive the sync request. However, it will refuse to process it. Why? Because sync4j use serverUri as part of its authentication protocol. Sync4j will load serverURI from its sync4j.properties configuration file and compare it with localURI from sync client in syncML. Therefore, sync4j server failure on processing the sync message as the serverUri from client side does not match the serverURI from sync4j.properties file.

We can see relevant code from sync4j client native code. In file SyncMLProcessor.cpp, around line 241, we can see some code like this,

uri = getElementContentSaveMem(target, TEXT("LocURI"), NULL, &startPos, &endPos);
        if ((uri == NULL) || (wcsncmp(uri, source.getName(NULL, 0), endPos - startPos) != 0)) {
            //
            // This Sync is for another source
            //
            target  = NULL;
            uri     = NULL;
            continue;
        }


However, it is not difficult to walk around this by modifying its SyncSessionHandler.java. But, this will broke Funambol's AGPL license. Fortunately, in sync4j, many things are configurable. Developer can actually develop their own syncSessionHandler class and registered it into sync4j server.

The above analysis only apply to sync4jServer version 2.3. This post is only based on what I can recall. Probably, it has been changed in new version of Funambol server. I do not have time to check it yet. But, you can pay attention on this unique sync server name requirement from sync4j server if you plan to sync through multiple subnet connected with multiple routers attached to different DNS servers' configurations. Also, BTW, the native sync client API library from Funambol does not support sync through proxy and proxy authentication. When I worked on it, I have to add my own code to support sync through proxy with proxy authentication. But, I am not sure if they have added features to support this in their new release. It will be interesting to have a look at it later.