james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joan Carles Nez <joancar...@indibil.com>
Subject System Load
Date Thu, 22 Feb 2001 10:18:42 GMT
Hi all,

   I have been playing with James and I am very impressed with its design
and stability.
I have been testing it with MySQL, Interbase and I am about to test it with
Oracle. I have written a stress test program which you can find at the end
of this message. When I push the server to handle heavy loads the JDBC driver
for Interbase starts to throws Exceptions when recovering blobs.

Question: Does James deal with system load limits? Looking at the source of 
sendmail I see that they use a function called "shouldQueue" which takes the
system load and if it is higher than 1 then it queues the message. It starts
to deliver more messages when the load goes under 1. In this way it protects
itself like transaction monitors do. With James I have seen my machine go to
load levels of 10 or higher. Does James have/need such functionality? 

Cheers,

       Joan Carles

package org.apache.james.testing;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

/**
 * Program that hammers a James server with multiple threads (5) at a rate
 * stablished in miliseconds (args[0]), a certain number of iterations (args[1]).
 * Two types of threads, SMTPSender which send a message for a particular user and
 * POPReceiver which reads all messages from a particular user and deletes them.
 *
 * @author Joan Carles Núñez  <joancarles@indibil.com>
 */
public class StressTesting {
    static String hostSender = "@mydomain.com";
    static String[][] user = {{"jordi","jordi"},{"xavier","xavier"},{"jc","jc"},{"hernan","hernan"},{"marcel","marcel"}};
    public static void main(String[] args) throws Throwable {
        int numThreads = user.length;
        int interval = 1000; 
        int iterations = 1000;
        if (args.length >= 1) interval = Integer.valueOf(args[0]).intValue();
        if (args.length >= 2) iterations = Integer.valueOf(args[1]).intValue();
        for (int i = 0; i < numThreads ; i++) { 
          SMTPSender sender = new SMTPSender("1.1.1.6",user[i][0],user[i][1],interval,iterations);
          POPReceiver receiver = new POPReceiver("1.1.1.6",user[i][0],user[i][1],interval,iterations);
          new Thread(sender).start();         
          new Thread(receiver).start();
        }
    }
}

class SMTPSender implements Runnable {
   private String mailHost;
   private String user;
   private String password;
   private int interval = 1000;
   private int iterations = 1000;
   private Properties prop = new Properties();
   private int messagesSentOk = 0;
   private int messagesWithException = 0;

   public SMTPSender (String host, String user, String password, int interval,int iterations)
{
        this.mailHost = host;
        this.user = user;
        this.password = password;
        this.interval = interval;
        this.iterations = iterations;
        prop.put("mail.smtp.host", mailHost);
   }

   public void run() {
        for (int i = 0; i < iterations ; i++) {
           sendMail(i); 
           try {
            Thread.currentThread().sleep(interval);
           } catch (Exception ex) {}
        }

        System.out.println("Summary: Messages Sent OK: " + messagesSentOk + ", Messages Failed:
" + messagesWithException);
   }
   
   /** Send a message with msgId as the subject */
   void sendMail(int msgId) {
        try {
            Session session = Session.getDefaultInstance(prop, null);
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(user+StressTesting.hostSender));
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(user+StressTesting.hostSender));
            msg.setContent("Hola mon", "text/plain");
            msg.setSubject(String.valueOf(msgId));
            Transport.send(msg);
            System.out.println("Sent message OK: " + msgId +
                    " from: " + msg.getFrom()[0] + " To: " +
                    msg.getAllRecipients()[0]);
            messagesSentOk++;
        } catch (Throwable e) {
            messagesWithException++;
            e.printStackTrace();
        }
    }
}

class POPReceiver implements Runnable {
   private String mailHost;
   private String user;
   private String password;
   private int interval = 1000;
   private int iterations = 1000;
   private Properties prop = new Properties();
   private int messagesReceivedOk = 0;
   private int messagesReceivedWithException = 0;

   public POPReceiver (String host, String user, String password, int interval,int iterations)
{
        this.mailHost = host;
        this.user = user;
        this.password = password;
        this.interval = interval;
        this.iterations = iterations;
        prop.put("java.smtp.host", mailHost);
   }

   public void run() {
        for (int i = 0; i < iterations ; i++) {
           receiveMail(true);
           try {
            Thread.currentThread().sleep(interval);
           } catch (Exception ex) {}
        }

        System.out.println("Summary: Messages Received OK: " + messagesReceivedOk + ", Messages
Failed: " + messagesReceivedWithException);
   }
  
   /** Receive Messages from POP3 server, Print details of each message, check that contents
are the
    *  the same as the message sent and delete each message if delete flag is true.
    */
   void receiveMail(boolean delete) {
        Store store = null;
        Folder folder = null; 
        try {
            // Fetch INBOX Folder
            Session session = Session.getDefaultInstance(prop, null);
            store = session.getStore("pop3");
            store.connect(mailHost, user, password);
            folder = store.getFolder("INBOX");
            if(folder == null || !folder.exists()) {
                System.out.println("This folder does not exist.");
                return;
            }
            folder.open(Folder.READ_WRITE);
            
            // Process Messages in INBOX folder
            Message[] msgs = folder.getMessages();
            System.out.println("Received " + msgs.length + " messages for " + user);
            for (int i = 0; i < msgs.length; i++) {
              Message msg = msgs[i];
              System.out.println("From: " + msg.getFrom()[0].toString() +"\nTo: " + msg.getRecipients(Message.RecipientType.TO)[0]
+ "\nSubject: " + msg.getSubject() + "\n-------------------");
              // Check that the contents have not been altered
              //if (msg.getContent().toString().length() != 1500000) System.out.println("Message
received with wrong size...");
               
              // Delete the message 
              if(delete) {
                msg.setFlag(Flags.Flag.DELETED, true);
                System.out.println(msg.getSubject() +" Deleted.");
              }
              messagesReceivedOk++;
            }
        } catch (MessagingException e) {
            e.printStackTrace();
            messagesReceivedWithException++;
        } catch (Throwable e) {
            e.printStackTrace();
            messagesReceivedWithException++;
        } finally {
           // Close folder and store...
           try { folder.close(true); store.close(); } catch (Throwable t) {}
        }
    }
}




Mime
View raw message