在 Linux 上本地化。20k 条消息大约需要 10 秒。我的猜测是我的 Java 很糟糕,而 Python 很好。
py客户端:
def scan(self, msg):
try:
print 'begin scan'
HOST = 'localhost'
PORT = 33000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT));
s.sendall(msg)
data = s.recv(1024)
s.close()
print 'Received', repr(data)
except Exception, e:
print "error: " + str(e)
Java服务器:
ServerSocket service = new ServerSocket(33000);
while(true) {
debug("Begin waiting for connection");
//this spins
Socket connection = service.accept();
debug("Connection received from " + connection.getInetAddress().getHostName());
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
ScanResultsHeader results = new ScanResultsHeader();
Scanner scanner = new Scanner();
results = scanner.scan("scannerfake@gmail.com", "123", in);
和
公共 ScanResultsHeader 扫描(字符串 userEmail、字符串 imapRetrievalId、BufferedInputStream mimeEmail)抛出 IOException、FileNotFoundException、MimeException、ScannerException {
//how fast would it be to just slurp up stream?
debug("slurp!");
String slurp = IOUtils.toString(mimeEmail);
debug("slurped " + slurp.length() + " characters");
slurp = slurp.toLowerCase();
debug("lc'ed it");
//...
我的猜测是我把输入流弄错了。一个问题是使用的库 API 扫描需要“BufferedInputStream mimeEmail”签名,因此我最终需要使用该表单。但我注意到啜食一根绳子的简单动作需要很长时间,所以我已经在做一些不正确的事情了。