[ 
https://issues.apache.org/jira/browse/DIRMINA-144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12540121
 ] 

Trustin Lee commented on DIRMINA-144:
-------------------------------------

You can test the throughput using the following sample application and netcat 
(UNIX nc) command:

public class TrafficShapingFilterTest {
    public static void main(String[] args) throws Exception {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
        
        SocketAcceptor acceptor = new NioSocketAcceptor();
        acceptor.getFilterChain().addLast(
                "traffic", 
                new TrafficShapingFilter(executor, 1024, 1024));
        acceptor.setHandler(new IoHandlerAdapter() {
            @Override
            public void messageReceived(IoSession session, Object message)
                    throws Exception {
                session.write(((IoBuffer) message).duplicate());
            }
            
            @Override
            public void sessionClosed(IoSession session) {
                long currentTime = System.currentTimeMillis();
                System.out.println("elapsedTime: " + (currentTime - 
session.getCreationTime()));
                System.out.println("readBytes: " + session.getReadBytes());
                System.out.println(
                        "readThroughput: " + session.getReadBytes() * 1000 / 
(currentTime - session.getCreationTime()));
                System.out.println("writtenBytes: " + 
session.getWrittenBytes());
                System.out.println(
                        "writeThroughput: " + session.getWrittenBytes() * 1000 
/ (currentTime - session.getCreationTime()));
            }
        });
        acceptor.setLocalAddress(new InetSocketAddress(8080));
        acceptor.bind();
    }
}


> Traffic shaping filter
> ----------------------
>
>                 Key: DIRMINA-144
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-144
>             Project: MINA
>          Issue Type: New Feature
>          Components: Filter
>            Reporter: Niklas Therning
>            Assignee: Trustin Lee
>            Priority: Minor
>             Fix For: 2.0.0-M1
>
>
> MINA now has basic support for suspending/resuming reads and writes on an 
> IoSession for all transport types. We should use this feature to implement a 
> traffic shaping filter which lets the user configure bandwidth limitations. 
> Both globally and for individual sessions. Here are some configuration 
> options I can come to think of:
> * Globally specify a maximum data rate for individual sessions (e.g. max 10 
> kb/s for all sessions).
> * Specify a maximum data rate on a per session basis (e.g. max 1 Mb/s for a 
> particular session).
> * Specify a maximum upper limit on the bandwidth used by all sessions in 
> total (e.g. all sessions share a total of 10 Mb/s).
> * Configure different traffic classes with different limits to allow for 
> high/low priority traffic and partition sessions into these priority classes.
> I'm not sure how advanced it would have to be so please share your thoughts. 
> Maybe point 1 and 2 would suffice? I think 3 and 4 add a lot of complexity 
> since they need some kind of scheduling algorithm to provide fairness between 
> sessions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to