ServerSideCachingOpsEmail

Serverside caching of projectGuid on message id

The idea is to store projectGuid with it's message id in a hashmap on the server. We can choose to store all message id, projectGuid, message uid and message folder or just store them after someone asked for one.

Note: Open source caching libraries all seem to require too much overhead(configuration, use) for our needs, so we will implement a simple caching system ourselves.

Storing projectGuid, message id(=key), foldername and message uid in a hashmap whenever we get a request for them.

  • Check the projectGuid - message id hashmap
  • if a none null value is returned
    • if the e-mail message is still in the selected folder
      • continue to checking with LDAP
    • else
      • remove the item from the hashtable and continue to search

  • search
    • search all accesible mailfolders with the message id
    • stop when the message is found
    • add entry to hashtable

  • check LDAP
    • see if the set projectGuid is visible to the current user and need to make sure the calling user is allowed to see this project by doing an LDAP search with the memberUid = username and projectGuid = projectGuid, if nothing is returns we return null instead of the projectGuid, else we return the projectGuid
    • else return null;

Downsides of this method is the first time the projectGuid is searched for on message id it takes just as long as before, we might need some timestamp on table entries so we can remove the last used ones else this can use increasing amounts of memory.

Tests

I've implemented server side caching and it seems to improve performance considerably, but there are still a few problems:
  • e-mail messages not assigned to a project still take a looooong time to display, the problem is we need to search all available mailfolders for the message to make sure it's not assigned to any project
  • first time when someone selects an e-mail message it's not cached yet, so still takes long
  • cache is never cleaned (only on restart), maybe there should be a scheduled task cleaning it (removing all entries above a certain amount), removing entries which haven't been been used the longest.
Some results for caching tests:
5625ms to retrieve an e-mail is not in any project folder.
2171ms to retrieve the projectGuid for an e-mail for the first time.
219ms to retrieve the projectGuid for an e-mail for the second time.

But that's not all!

Because using this caching system we still have very slow results on e-mail messages not assigned to a project. To solve this we have to make sure our cache is up to date. We can do this using an IMAP proxy, which can update the cache at every copy, append or expunge action. caching3b.jpg

How does it work

At each passing IMAP command we check if it is something we should be aware of and take action if it is. ImapProxy overview
  • The gray rectangles represent IMAP commands
  • The blue ones the information we take from the command
  • The white ones the information we need additionally
  • The dark gray rectangle represents the cache database

Implementation

The IMAP proxy consists of a class which listens for client connections, when a connection is made, the IMAP proxy tries to set up a connection to the IMAP server, if this succeeds both connections are passed on to another thread which will deal with the connection from there on. If the connection with the IMAP server fails the client connection will be closed without a message, triggering a connection error at the client. When IMAP commands are send from server to client or the other way around these are evaluated, if necesarry updates to the OPS cache database are performed and then the messages passed on.

imapproxyclasses2.jpg
The image above shows the IMAP client connecting with the IMAP proxy and the IMAP proxy classes handle this connection.

SSL

Getting SSL to work was quite a haSSLe smile , the main problem beeing setting up the certificates and using them. I have created a script for generating the client and server certificates and placing them in a keystore, which will be used by the IMAP proxy.

Links

  • GavaMail - GavaMail is an e-mail proxy program between POP3(and IMAP) and GMail.
  • GavaMail CVS - CVS contains an IMAP proxy for GavaMail
  • HSQLDB - The database we plan on using

-- BastiaanGrutters - 20 Dec 2005

Topic revision: r5 - 13 Jan 2006 - 15:54:52 - BastiaanGrutters
Developers.ServerSideCachingOpsEmail moved from Developers.ServerSideCaching on 20 Dec 2005 - 13:38 by BastiaanGrutters - put it back

tip TWiki Tip of the Day
Raw Text link
At the bottom of the page next to Edit and Attach , there is a Raw Text link that allows one to ... Read on Read more

 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback