We need advice on server software implementation using java NiO

I'm trying to calculate the load on the server I have to build

I need to create a server and register one million users in the SQL database Within a week, each user will connect about 3-4 times It may take 1-2 minutes each time the user starts and downloads 1-30 MB of data

After uploading, it will be deleted in a few minutes (update text deletion error in calculation)

I know how to make and query SQL database, but what should I consider in this case?

resolvent

Solution

I am using netty to implement a similar scheme It's just work!

Here is the starting point for using netty:

public class TCPListener {
    private static ServerBootstrap bootstrap;

    public static void run(){
        bootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),Executors.newCachedThreadPool()));

        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                TCPListnerHandler handler = new MyHandler();
                ChannelPipeline pipeline = Channels.pipeline();
                pipeline.addLast("handler",handler);

                return pipeline;
            }
        });

        bootstrap.bind(new InetSocketAddress(9999));  //port number is 9999
    }

    public static void main(String[] args) throws Exception {
        run();
    }
}

And myhandler classes:

public class MyHandler extends SimpleChannelUpstreamHandler {
    @Override
    public void messageReceived(
        ChannelHandlerContext ctx,MessageEvent e) {


        try {
            String remoteAddress = e.getRemoteAddress().toString();
            ChannelBuffer buffer= (ChannelBuffer) e.getMessage();
            //Now the buffer contains byte stream from client.

        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        }

        byte[] output; //suppose output is a filled byte array
        ChannelBuffer writebuffer = ChannelBuffers.buffer(output.length);
        for (int i = 0; i < output.length; i++) {
            writebuffer.writeByte(output[i]);
        }


        e.getChannel().write(writebuffer);
    }

    @Override
    public void exceptionCaught(
            ChannelHandlerContext ctx,ExceptionEvent e) {
        // Close the connection when an exception is raised.
        e.getChannel().close();
    }
}

The above is all the contents of the suggestions we need to implement the server software using java NiO collected and sorted out by the programming home for you. I hope this article can help you solve the program development problems we encounter when we need the suggestions on implementing the server software using java NiO.

If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>