Search in sources :

Example 1 with MemberImpl

use of org.apache.catalina.tribes.membership.MemberImpl in project tomcat by apache.

the class SocketNioSend method main.

public static void main(String[] args) throws Exception {
    Selector selector = Selector.open();
    Member mbr = new MemberImpl("localhost", 9999, 0);
    ChannelData data = new ChannelData();
    data.setOptions(Channel.SEND_OPTIONS_BYTE_MESSAGE);
    data.setAddress(mbr);
    byte[] buf = new byte[8192 * 4];
    data.setMessage(new XByteBuffer(buf, false));
    buf = XByteBuffer.createDataPackage(data);
    int len = buf.length;
    BigDecimal total = new BigDecimal((double) 0);
    BigDecimal bytes = new BigDecimal((double) len);
    NioSender sender = new NioSender();
    sender.setDestination(mbr);
    sender.setDirectBuffer(true);
    sender.setSelector(selector);
    sender.setTxBufSize(1024 * 1024);
    sender.connect();
    sender.setMessage(buf);
    System.out.println("Writing to 9999");
    long start = 0;
    double mb = 0;
    boolean first = true;
    int count = 0;
    DecimalFormat df = new DecimalFormat("##.00");
    while (count < 100000) {
        if (first) {
            first = false;
            start = System.currentTimeMillis();
        }
        sender.setMessage(buf);
        int selectedKeys = 0;
        try {
            selectedKeys = selector.select(0);
        } catch (Exception e) {
            e.printStackTrace();
            continue;
        }
        if (selectedKeys == 0) {
            continue;
        }
        Iterator<SelectionKey> it = selector.selectedKeys().iterator();
        while (it.hasNext()) {
            SelectionKey sk = it.next();
            it.remove();
            try {
                int readyOps = sk.readyOps();
                sk.interestOps(sk.interestOps() & ~readyOps);
                if (sender.process(sk, false)) {
                    total = total.add(bytes);
                    sender.reset();
                    sender.setMessage(buf);
                    mb += ((double) len) / 1024 / 1024;
                    if (((++count) % 10000) == 0) {
                        long time = System.currentTimeMillis();
                        double seconds = ((double) (time - start)) / 1000;
                        System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, total " + mb + " MB, total " + total + " bytes.");
                    }
                }
            } catch (Throwable t) {
                t.printStackTrace();
                return;
            }
        }
        selector.selectedKeys().clear();
    }
    System.out.println("Complete, sleeping 15 seconds");
    Thread.sleep(15000);
}
Also used : SelectionKey(java.nio.channels.SelectionKey) XByteBuffer(org.apache.catalina.tribes.io.XByteBuffer) NioSender(org.apache.catalina.tribes.transport.nio.NioSender) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal) ChannelData(org.apache.catalina.tribes.io.ChannelData) Member(org.apache.catalina.tribes.Member) Selector(java.nio.channels.Selector)

Example 2 with MemberImpl

use of org.apache.catalina.tribes.membership.MemberImpl in project tomcat by apache.

the class SocketNioValidateSend method main.

public static void main(String[] args) throws Exception {
    Selector selector = Selector.open();
    Member mbr = new MemberImpl("localhost", 9999, 0);
    byte seq = 0;
    byte[] buf = new byte[50000];
    Arrays.fill(buf, seq);
    int len = buf.length;
    BigDecimal total = new BigDecimal((double) 0);
    BigDecimal bytes = new BigDecimal((double) len);
    NioSender sender = new NioSender();
    sender.setDestination(mbr);
    sender.setDirectBuffer(true);
    sender.setSelector(selector);
    sender.connect();
    sender.setMessage(buf);
    System.out.println("Writing to 9999");
    long start = 0;
    double mb = 0;
    boolean first = true;
    int count = 0;
    DecimalFormat df = new DecimalFormat("##.00");
    while (count < 100000) {
        if (first) {
            first = false;
            start = System.currentTimeMillis();
        }
        sender.setMessage(buf);
        int selectedKeys = 0;
        try {
            selectedKeys = selector.select(0);
        } catch (Exception e) {
            e.printStackTrace();
            continue;
        }
        if (selectedKeys == 0) {
            continue;
        }
        Iterator<SelectionKey> it = selector.selectedKeys().iterator();
        while (it.hasNext()) {
            SelectionKey sk = it.next();
            it.remove();
            try {
                int readyOps = sk.readyOps();
                sk.interestOps(sk.interestOps() & ~readyOps);
                if (sender.process(sk, false)) {
                    total = total.add(bytes);
                    sender.reset();
                    seq++;
                    Arrays.fill(buf, seq);
                    sender.setMessage(buf);
                    mb += ((double) len) / 1024 / 1024;
                    if (((++count) % 10000) == 0) {
                        long time = System.currentTimeMillis();
                        double seconds = ((double) (time - start)) / 1000;
                        System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, total " + mb + " MB, total " + total + " bytes.");
                    }
                }
            } catch (Throwable t) {
                t.printStackTrace();
                return;
            }
        }
    }
    System.out.println("Complete, sleeping 15 seconds");
    Thread.sleep(15000);
}
Also used : SelectionKey(java.nio.channels.SelectionKey) NioSender(org.apache.catalina.tribes.transport.nio.NioSender) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal) Member(org.apache.catalina.tribes.Member) Selector(java.nio.channels.Selector)

Example 3 with MemberImpl

use of org.apache.catalina.tribes.membership.MemberImpl in project tomcat by apache.

the class SocketSend method main.

public static void main(String[] args) throws Exception {
    Member mbr = new MemberImpl("localhost", 9999, 0);
    ChannelData data = new ChannelData();
    data.setOptions(Channel.SEND_OPTIONS_BYTE_MESSAGE);
    data.setAddress(mbr);
    byte[] buf = new byte[8192 * 4];
    data.setMessage(new XByteBuffer(buf, false));
    buf = XByteBuffer.createDataPackage(data);
    int len = buf.length;
    System.out.println("Message size:" + len + " bytes");
    BigDecimal total = new BigDecimal((double) 0);
    BigDecimal bytes = new BigDecimal((double) len);
    try (Socket socket = new Socket("localhost", 9999)) {
        System.out.println("Writing to 9999");
        OutputStream out = socket.getOutputStream();
        long start = 0;
        double mb = 0;
        boolean first = true;
        int count = 0;
        DecimalFormat df = new DecimalFormat("##.00");
        while (count < 1000000) {
            if (first) {
                first = false;
                start = System.currentTimeMillis();
            }
            out.write(buf, 0, buf.length);
            mb += ((double) buf.length) / 1024 / 1024;
            total = total.add(bytes);
            if (((++count) % 10000) == 0) {
                long time = System.currentTimeMillis();
                double seconds = ((double) (time - start)) / 1000;
                System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds messages " + count + ", total " + mb + " MB, total " + total + " bytes.");
            }
        }
        out.flush();
        System.out.println("Complete, sleeping 5 seconds");
        Thread.sleep(5000);
    }
}
Also used : XByteBuffer(org.apache.catalina.tribes.io.XByteBuffer) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) OutputStream(java.io.OutputStream) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal) ChannelData(org.apache.catalina.tribes.io.ChannelData) Member(org.apache.catalina.tribes.Member) Socket(java.net.Socket)

Example 4 with MemberImpl

use of org.apache.catalina.tribes.membership.MemberImpl in project tomcat by apache.

the class ChannelCreator method createChannel.

public static Channel createChannel(String[] args) throws Exception {
    String bind = "auto";
    int port = 4001;
    String mbind = null;
    boolean gzip = false;
    int tcpseltimeout = 5000;
    int tcpthreadcount = 4;
    int acktimeout = 15000;
    String mcastaddr = "228.0.0.5";
    int mcastport = 45565;
    long mcastfreq = 500;
    long mcastdrop = 2000;
    boolean order = false;
    int ordersize = Integer.MAX_VALUE;
    boolean frag = false;
    int fragsize = 1024;
    int autoBind = 10;
    ArrayList<Member> staticMembers = new ArrayList<>();
    Properties transportProperties = new Properties();
    String transport = "org.apache.catalina.tribes.transport.nio.PooledParallelSender";
    String receiver = "org.apache.catalina.tribes.transport.nio.NioReceiver";
    boolean async = false;
    //50MB
    int asyncsize = 1024 * 1024 * 50;
    boolean throughput = false;
    boolean failuredetect = false;
    for (int i = 0; i < args.length; i++) {
        if ("-bind".equals(args[i])) {
            bind = args[++i];
        } else if ("-port".equals(args[i])) {
            port = Integer.parseInt(args[++i]);
        } else if ("-autobind".equals(args[i])) {
            autoBind = Integer.parseInt(args[++i]);
        } else if ("-tcpselto".equals(args[i])) {
            tcpseltimeout = Integer.parseInt(args[++i]);
        } else if ("-tcpthreads".equals(args[i])) {
            tcpthreadcount = Integer.parseInt(args[++i]);
        } else if ("-gzip".equals(args[i])) {
            gzip = true;
        } else if ("-async".equals(args[i])) {
            async = true;
        } else if ("-failuredetect".equals(args[i])) {
            failuredetect = true;
        } else if ("-asyncsize".equals(args[i])) {
            asyncsize = Integer.parseInt(args[++i]);
            System.out.println("Setting MessageDispatchInterceptor.maxQueueSize=" + asyncsize);
        } else if ("-static".equals(args[i])) {
            String d = args[++i];
            String h = d.substring(0, d.indexOf(':'));
            String p = d.substring(h.length() + 1);
            Member m = new MemberImpl(h, Integer.parseInt(p), 2000);
            staticMembers.add(m);
        } else if ("-throughput".equals(args[i])) {
            throughput = true;
        } else if ("-order".equals(args[i])) {
            order = true;
        } else if ("-ordersize".equals(args[i])) {
            ordersize = Integer.parseInt(args[++i]);
            System.out.println("Setting OrderInterceptor.maxQueue=" + ordersize);
        } else if ("-frag".equals(args[i])) {
            frag = true;
        } else if ("-fragsize".equals(args[i])) {
            fragsize = Integer.parseInt(args[++i]);
            System.out.println("Setting FragmentationInterceptor.maxSize=" + fragsize);
        } else if ("-ackto".equals(args[i])) {
            acktimeout = Integer.parseInt(args[++i]);
        } else if ("-transport".equals(args[i])) {
            transport = args[++i];
        } else if (args[i] != null && args[i].startsWith("transport.")) {
            String key = args[i];
            String val = args[++i];
            transportProperties.setProperty(key, val);
        } else if ("-receiver".equals(args[i])) {
            receiver = args[++i];
        } else if ("-maddr".equals(args[i])) {
            mcastaddr = args[++i];
        } else if ("-mport".equals(args[i])) {
            mcastport = Integer.parseInt(args[++i]);
        } else if ("-mfreq".equals(args[i])) {
            mcastfreq = Long.parseLong(args[++i]);
        } else if ("-mdrop".equals(args[i])) {
            mcastdrop = Long.parseLong(args[++i]);
        } else if ("-mbind".equals(args[i])) {
            mbind = args[++i];
        }
    }
    System.out.println("Creating receiver class=" + receiver);
    Class<?> cl = Class.forName(receiver, true, ChannelCreator.class.getClassLoader());
    ReceiverBase rx = (ReceiverBase) cl.newInstance();
    rx.setAddress(bind);
    rx.setPort(port);
    rx.setSelectorTimeout(tcpseltimeout);
    rx.setMaxThreads(tcpthreadcount);
    rx.setMinThreads(tcpthreadcount);
    rx.getBind();
    rx.setRxBufSize(43800);
    rx.setTxBufSize(25188);
    rx.setAutoBind(autoBind);
    ReplicationTransmitter ps = new ReplicationTransmitter();
    System.out.println("Creating transport class=" + transport);
    MultiPointSender sender = (MultiPointSender) Class.forName(transport, true, ChannelCreator.class.getClassLoader()).newInstance();
    sender.setTimeout(acktimeout);
    sender.setMaxRetryAttempts(2);
    sender.setRxBufSize(43800);
    sender.setTxBufSize(25188);
    Iterator<Object> i = transportProperties.keySet().iterator();
    while (i.hasNext()) {
        String key = (String) i.next();
        IntrospectionUtils.setProperty(sender, key, transportProperties.getProperty(key));
    }
    ps.setTransport(sender);
    McastService service = new McastService();
    service.setAddress(mcastaddr);
    if (mbind != null)
        service.setMcastBindAddress(mbind);
    service.setFrequency(mcastfreq);
    service.setMcastDropTime(mcastdrop);
    service.setPort(mcastport);
    ManagedChannel channel = new GroupChannel();
    channel.setChannelReceiver(rx);
    channel.setChannelSender(ps);
    channel.setMembershipService(service);
    if (throughput)
        channel.addInterceptor(new ThroughputInterceptor());
    if (gzip)
        channel.addInterceptor(new GzipInterceptor());
    if (frag) {
        FragmentationInterceptor fi = new FragmentationInterceptor();
        fi.setMaxSize(fragsize);
        channel.addInterceptor(fi);
    }
    if (order) {
        OrderInterceptor oi = new OrderInterceptor();
        oi.setMaxQueue(ordersize);
        channel.addInterceptor(oi);
    }
    if (async) {
        MessageDispatchInterceptor mi = new MessageDispatchInterceptor();
        mi.setMaxQueueSize(asyncsize);
        channel.addInterceptor(mi);
        System.out.println("Added MessageDispatchInterceptor");
    }
    if (failuredetect) {
        TcpFailureDetector tcpfi = new TcpFailureDetector();
        channel.addInterceptor(tcpfi);
    }
    if (staticMembers.size() > 0) {
        StaticMembershipInterceptor smi = new StaticMembershipInterceptor();
        for (int x = 0; x < staticMembers.size(); x++) {
            smi.addStaticMember(staticMembers.get(x));
        }
        channel.addInterceptor(smi);
    }
    byte[] domain = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    ((McastService) channel.getMembershipService()).setDomain(domain);
    DomainFilterInterceptor filter = new DomainFilterInterceptor();
    filter.setDomain(domain);
    channel.addInterceptor(filter);
    return channel;
}
Also used : ReceiverBase(org.apache.catalina.tribes.transport.ReceiverBase) MultiPointSender(org.apache.catalina.tribes.transport.MultiPointSender) StaticMembershipInterceptor(org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor) ArrayList(java.util.ArrayList) FragmentationInterceptor(org.apache.catalina.tribes.group.interceptors.FragmentationInterceptor) TcpFailureDetector(org.apache.catalina.tribes.group.interceptors.TcpFailureDetector) Properties(java.util.Properties) GzipInterceptor(org.apache.catalina.tribes.group.interceptors.GzipInterceptor) OrderInterceptor(org.apache.catalina.tribes.group.interceptors.OrderInterceptor) ManagedChannel(org.apache.catalina.tribes.ManagedChannel) Member(org.apache.catalina.tribes.Member) DomainFilterInterceptor(org.apache.catalina.tribes.group.interceptors.DomainFilterInterceptor) MessageDispatchInterceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) ReplicationTransmitter(org.apache.catalina.tribes.transport.ReplicationTransmitter) ThroughputInterceptor(org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor) McastService(org.apache.catalina.tribes.membership.McastService)

Example 5 with MemberImpl

use of org.apache.catalina.tribes.membership.MemberImpl in project tomcat by apache.

the class NioSenderTest method init.

public void init() throws Exception {
    selector = Selector.open();
    mbr = new MemberImpl("localhost", 4444, 0);
    NioSender sender = new NioSender();
    sender.setDestination(mbr);
    sender.setDirectBuffer(true);
    sender.setSelector(selector);
    sender.setMessage(XByteBuffer.createDataPackage(getMessage(mbr)));
    sender.connect();
}
Also used : NioSender(org.apache.catalina.tribes.transport.nio.NioSender) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl)

Aggregations

MemberImpl (org.apache.catalina.tribes.membership.MemberImpl)6 Member (org.apache.catalina.tribes.Member)5 BigDecimal (java.math.BigDecimal)3 DecimalFormat (java.text.DecimalFormat)3 ChannelData (org.apache.catalina.tribes.io.ChannelData)3 XByteBuffer (org.apache.catalina.tribes.io.XByteBuffer)3 NioSender (org.apache.catalina.tribes.transport.nio.NioSender)3 SelectionKey (java.nio.channels.SelectionKey)2 Selector (java.nio.channels.Selector)2 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ManagedChannel (org.apache.catalina.tribes.ManagedChannel)1 GroupChannel (org.apache.catalina.tribes.group.GroupChannel)1 DomainFilterInterceptor (org.apache.catalina.tribes.group.interceptors.DomainFilterInterceptor)1 FragmentationInterceptor (org.apache.catalina.tribes.group.interceptors.FragmentationInterceptor)1 GzipInterceptor (org.apache.catalina.tribes.group.interceptors.GzipInterceptor)1 MessageDispatchInterceptor (org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor)1 OrderInterceptor (org.apache.catalina.tribes.group.interceptors.OrderInterceptor)1