Cayenne User Documentation
Turning off Context Synchronization

A big part of commit operation is updating peer DataContexts with the changes committed to the database. The conext synchronization operation has `O(N)` performance, where `N` is the number of peer DataContexts. In a web application `N` is often the number of concurrent sessions, which can be quite big. The throughout of high volume applications can be improved by turning off peer synchronization. One possible way to do that is via a custom DataContextFactory:

    public class IsolatedDataContextFactory implements DataContextFactory {

        public DataContext createDataContext(DataChannel parent, ObjectStore objectStore) {

            // stop listening for peer events
            parent.getEventManager().removeListener(objectStore);
            return new DataContext(parent, objectStore);
        }
    }

Of course doing this may result in some stale data in the peer DataContexts, so a decision whether to use this particular technique should be made based on the application specifics. Also a factory can have logic to selectively turn off synchronization for a subset of DataContexts based on some criteria.

| Don't use this for idle applications Note that this optimization does not affect percieved user commit time, as synchronization is done in a separate thread. It only affects the overall throughput. So it only makes sense if your application already utilizes close to a 100% of CPU.

Further improvements in this area are tracked via CAY-554 Jira issue.

.
Copyright ©2001-2007 Apache Software Foundation