tags:

views:

222

answers:

1

I'm developing a web application which acts as an email client for mobile. In this application user can login and provide numerous email ids for monitoring.There are two main classes in the web application. 1.MailGetter 2.MailFormatter

Behaviour of MailGetter class:

  1. Timertask initiated which will execute for every 10 minutes
  2. Obtains the numerous email ids from database which are provided for monitoring
  3. establishes connection with mail server for the first email id and obtains recently arrived email message object
  4. passes the message object to MailFormatter class

Behavior of MailFormatter class:

  1. parses the email message object
  2. various recursive calls made if the message has many multiparts inorder to parse parts one by one
  3. downloads also attachments along with this message
  4. returns an xml string to the MailGetter class which will be stored as simple text file with the following content:

Example:

<mail>
<from>FromEmailID</from>
<to>ToEmailID</to>
<subject>Subject</subject>
<body>Email Body</body>
<attachments>
  attachment
</attachments>
</mail>

MobileResponderServlet: A separate servlet is also coded in the web application which will read the simple xml text file and send the read content to mobile

The main demerit of this application might be "MailGetter" class will be waiting until all the functions (including recursive calls) of "MailFormatter" class finishes execution.Once the control is returned from "MailFormatter" class to "MailGetter" class, it will obtain the next message object from mail server and passes it to "MailFormatter" class.So intimating about new emails to the mobile user consumes time. Even when "MailFormatter" class is implemented as a separate thread,consider in a case if there are 1000 new emails in a single inbox (for a single emailid) which will be invocating 1000 "MailFormatter" threads, which will make the process more resource intensive.

So I'm deciding to unplug "MailFormatter" from "MailGetter". "MailGetter" will be running as a separate web application in one server whereas "MailFormatter" will be running as a separate web application in another server. After obtaining the recent email message object "MailGetter" web application persists (via message.writeTo(FileOutputstream)) the message object in a location which is also common to "MailFormatter". "MailFormatter" class then reads (via MimeMessage(Session,InputStream) constructor) and parses the message object one by one and then stores the "XML Content" in another location which will be read by "MobileResponderServlet" and sent to mobile.

Will this process be efficient in real time? Will this be arising problems especially while sharing message objects between "MailGetter" and "MailFormatter" web applications? Please do let me know if there are any other ways. This web application will be handling more than 5000 users (minimum) who have provided numerous email ids for monitoring.

A: 

I think the only practical thing you can do is put together some test scenario. The above has too many variables to warrant a practical answer relating to performance.

Put together a source mailbox that has a set of test emails, then knock together some simple mechanism to query this, dump your messages out, and then use your second process to consume. This mechanism would most likely not be your complete solution, but should be representative.

It would be a good idea to make this repeatable and consistent, so as you implement your real solution, you can study whether it's getting slower, and/or benchmark and measure consistently.

Brian Agnew