RE: Multi Thead Producer
"Tamoyo Vitali" <tamoyo.vitali-+4n8Pjbed72QlJb33dTly1/I71DsQ//[email protected]>
| Newsgroups | gmane.comp.java.openjms.devel |
|---|---|
| Message-ID | <66150DEA041C2D4CA39D7096B032126C9780AD@exchange.supportcomm.com.br> |
Thanks Jim 8^D!!
I agree with you, it seems to be synchronization but I can't imagine where it is occurring. Remeber when I run 2 separates process (with one thread each one) the time are not affected. I am running on a pentium 4 1ghz hadhat 7.3 1gb ram with mysql Ver 11.18 Distrib 3.23.56 and tcp connection and I got 1 msg 80 mileseconds so 1 sec = 12,5 messages, but this time does not change if I run different processes at the same time. (I am sory to be repetitive!!!)
this is a very simple code, I forgot mentioned I use tcp connection, please take a look at the code below :
import javax.naming.*;
import javax.jms.*;
import java.util.*;
import java.io.*;
import java.net.*;
public class queue2 extends Thread {
private static String arg;
int q;
private static long max =0;
long ini;
private String url = "tcp://192.168.255.81:3035";
private String modeType = "org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory";
private String queue_name = null;
private QueueConnectionFactory factory = null;
private QueueConnection connection = null;
private QueueSession session = null;
private Queue queue = null;
private QueueSender sender = null;
private TextMessage message = null;
private Properties props = null;
private Context context = null;
private int priority = 9;
//private static long timeToLive = 20000;
private String TEXTO_MSGS = "apenas um teste";
queue2 (int i) { q=i;}
public void run() {
int ii =0 ;
ini = System.currentTimeMillis();
queue_name = "fila0";
try {
props = new Properties();
props.put(Context.PROVIDER_URL,url);//url
props.put(Context.INITIAL_CONTEXT_FACTORY,modeType); //modeType
} catch (Exception e) {
e.printStackTrace(System.err);
}
try {
context = new InitialContext(props);
factory = (QueueConnectionFactory)context.lookup("JmsQueueConnectionFactory");
} catch (NamingException e) {
e.printStackTrace(System.err);
}
try {
if( factory != null ) {
connection = factory.createQueueConnection();
connection.start();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); //(true, 0)
queue = (Queue)context.lookup(queue_name);
sender = session.createSender(queue);
int delivery_mode = DeliveryMode.PERSISTENT; //DeliveryMode.PERSISTENT;
for (ii = 0; ii<500;ii++) {
ini = System.currentTimeMillis() ;
message = session.createTextMessage();
message.setText( TEXTO_MSGS );
//sender.send(message, delivery_mode, priority, 0); //Nao enviar assim qdo usar o OpenJMS
sender.send( message );
ini = System.currentTimeMillis() - ini ;
System.out.println(q + " " + ii + " end " + ini);
}
}
} catch (JMSException e) {
System.out.println("Exception JMSException occurred: " + e.toString());
e.printStackTrace();
} catch (javax.naming.NamingException NaEx) {
System.out.println("Exception NamingException occurred: " + NaEx.toString());
NaEx.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {}
}
}
}
public static void main(String args[]) {
Thread t;
for (int i=0; i<1; i++) {
t = new queue2(i);
t.start();
}
}
}
Tamoyo C. Vitali Jr.
Gerente de Desenvolvimento
SupportComm
Rua da Assembléia, 100 - 19 Andar
Rio de Janeiro, RJ 20011-000
Tel: +55 21 3806-3340 / Cel: +55 21 8123-5182
mailto:tamoyo.vitali-+4n8Pjbed72QlJb33dTly1/I71DsQ//[email protected]
www.supportcomm.com.br
-----Original Message-----
From: Jim Alateras [mailto:[email protected]]
Sent: segunda-feira, 14 de abril de 2003 18:14
To: Tamoyo Vitali; openjms-developer-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: RE: [openjms-developer] Multi Thead Producer
Are you running the OpenJMS server with tcp or rmi? The only way I can
explain it, without looking at the code, is that there seems to be related
to synchronization either in your code, the OpenJMS client library or the
OpenJMS server.
cheers
</jima>
> -----Original Message-----
> From: openjms-developer-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> [mailto:openjms-developer-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org]On Behalf Of
> Tamoyo Vitali
> Sent: Tuesday, April 15, 2003 6:16 AM
> To: openjms-developer-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> Subject: [openjms-developer] Multi Thead Producer
>
>
> Hi all!!
>
> I am writing a java program to send messages to a queue in a
> multithread scenario. Each thread has exclusive objects such as
> connection, queue, sender, session. Inside each thread there is a
> loop that sends sequentially messages. When I run this program
> witha single thread, the time to send each message in a
> persistent autoacknolodge mode is 80 miliseconds, When I run the
> same program with 2 theads the time to send each message
> increases to 160 ms, with 3 theads it goes to 240 ms, with 4
> threads 320 ms a so on... This is the expected results (the time
> to deliver increases deppendin on the number os queuesenders) ???
> Is I run the same program in two diferents processes each one
> with just one thread they ane not affected and both takes 80 ms
> for each message) Am I doind any wrong?
>
> best regards!!!
>
> Tamoyo C. Vitali Jr.
> Gerente de Desenvolvimento
> SupportComm
>
> Rua da Assembléia, 100 - 19 Andar
> Rio de Janeiro, RJ 20011-000
> Tel: +55 21 3806-3340 / Cel: +55 21 8123-5182
> mailto:tamoyo.vitali-+4n8Pjbed72QlJb33dTly1/I71DsQ//[email protected]
> www.supportcomm.com.br
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> openjms-developer mailing list
> openjms-developer-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/openjms-developer