我正在尝试计算我必须构建的服务器上的负载。
我需要创建一个在SQL数据库中注册了一百万用户的服务器。在一周内,每个用户大约会连接3-4次。每次用户上传并下载1-30兆字节的数据,可能需要1-2分钟。
上传完成后,将在几分钟内将其删除。(计算中的更新文本删除错误)
我知道如何创建和查询SQL数据库,但在这种情况下应该考虑什么?
发布于 2011-06-03 16:16:26
我正在使用Netty来处理类似的场景。它只是起作用了!
下面是一个使用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();
}
}和MyHandler类:
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();
}
}发布于 2011-06-03 16:05:00
您真正想要的是Netty。它是一个用NIO编写的API,提供了另一个事件驱动模型,而不是经典的线程模型。它不为每个请求使用线程,但它将请求放入队列中。使用此工具,您可以每秒发出多达250,000个请求。
发布于 2011-06-03 16:22:52
一开始我认为这么多用户需要非阻塞解决方案,但我的计算表明我不需要,我说的对吗?
在现代操作系统和硬件上,thread-per-connection is faster than non-blocking I/O,至少除非连接数达到真正的极端水平。但是,对于将数据写入磁盘,NIO (通道和缓冲区)可能会有所帮助,因为它可以使用DMA并避免复制操作。
但总的来说,我也认为网络带宽和存储是这个应用程序的主要关注点。
https://stackoverflow.com/questions/6224414
复制相似问题