1

申し訳ありませんが、私はJavaに比較的慣れていません。zeromq (jeromq) を使用して Java アプリケーションから Logstash にログを送信するためのライブラリを作成しています。

私のテスト サーバーの 1 つは、Tomcat で実行されているビジー状態の Jenkins マスターです。私のライブラリ「Logit」( https://github.com/stuart-warren/logit ) は、(いくつかの基本的な負荷分散のために) Logstash エンドポイントの構成済みリストに JSON 形式のログ (JUL) をスプレーします。速度。

残念ながら、数日後に例外が発生します。Tomcat/Jenkins は引き続き動作し、通常のファイルにログを書き込みますが、Logit はネットワーク経由でメッセージを送信しなくなります。

18-Nov-2013 14:45:24 hudson.model.Run execute
INFO: EmployeeManagementSystems » Project Phase 2 branch » Int Tests » Sync Int Tests (Project - Prl) #326 aborted
java.lang.InterruptedException
        at java.lang.Object.wait(Native Method)
        at hudson.remoting.Request.call(Request.java:146)
        at hudson.remoting.Channel.call(Channel.java:714)
        at hudson.maven.ProcessCache$MavenProcess.call(ProcessCache.java:156)
        at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:815)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:565)
        at hudson.model.Run.execute(Run.java:1592)
        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:508)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:237)
logit:WARN IOException thrown, will try sending log again shortly.
zmq.ZError$IOException: java.nio.channels.ClosedByInterruptException
        at zmq.Signaler.send(Signaler.java:108)
        at zmq.Mailbox.send(Mailbox.java:90)
        at zmq.Ctx.send_command(Ctx.java:351)
        at zmq.ZObject.send_command(ZObject.java:364)
        at zmq.ZObject.send_activate_read(ZObject.java:217)
        at zmq.Pipe.flush(Pipe.java:284)
        at zmq.LB.send(LB.java:120)
        at zmq.Push.xsend(Push.java:64)
        at zmq.SocketBase.send(SocketBase.java:598)
        at org.jeromq.ZMQ$Socket.send(ZMQ.java:932)
        at com.stuartwarren.logit.zmq.ZmqTransport.appendString(ZmqTransport.java:115)
        at com.stuartwarren.logit.jul.ZmqAppender.publish(ZmqAppender.java:77)
        at java.util.logging.Logger.log(Logger.java:481)
        at java.util.logging.Logger.doLog(Logger.java:503)
        at java.util.logging.Logger.log(Logger.java:592)
        at hudson.model.Run.execute(Run.java:1610)
        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:508)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:237)
Caused by: java.nio.channels.ClosedByInterruptException
        at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:184)
        at sun.nio.ch.SinkChannelImpl.write(SinkChannelImpl.java:154)
        at zmq.Signaler.send(Signaler.java:106)
        ... 18 more
logit:ERROR Logit got interrupted while waiting to send failed message again.
java.lang.InterruptedException: sleep interrupted
        at java.lang.Thread.sleep(Native Method)
        at com.stuartwarren.logit.zmq.ZmqTransport.appendString(ZmqTransport.java:121)
        at com.stuartwarren.logit.jul.ZmqAppender.publish(ZmqAppender.java:77)
        at java.util.logging.Logger.log(Logger.java:481)
        at java.util.logging.Logger.doLog(Logger.java:503)
        at java.util.logging.Logger.log(Logger.java:592)
        at hudson.model.Run.execute(Run.java:1610)
        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:508)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:237)
18-Nov-2013 14:45:35 hudson.model.Run execute

テスト用の 6 ノードの Cassandra クラスターから同じバージョンのライブラリ ログを使用しています (log4j)。

私の質問は、メッセージを送信するときに上記のような例外をどのように処理すればよいですか? https://github.com/stuart-warren/logit/blob/master/src/main/java/com/stuartwarren/logit/zmq/ZmqTransport.java#L115 .

public void appendString(final String line) {
    final String log = line.substring(0, line.length() - 1);
    if (LogitLog.isTraceEnabled()) {
        LogitLog.trace("Sending log: [" + log + "].");
    }
    try {
        socket.send(log, ZMQ.NOBLOCK);
        // Has occasionally been known to throw a java.nio.channels.ClosedByInterruptException
    } catch (IOException e) {
        LogitLog.warn("IOException thrown, will try sending log again shortly.", e);
        // Try again after sleeping for a second
        try {
            Thread.sleep(1000);
            socket.send(log, ZMQ.NOBLOCK);
        } catch (InterruptedException i) {
            LogitLog.error("Logit got interrupted while waiting to send failed message again.", i);
        } catch (IOException e2) {
            LogitLog.error("Could not send following log on the second attempt: [" + log + "].", e2);
        }
    } catch (Exception g) {
        LogitLog.error("Something threw an exception that wasn't IOException.", g);
    }
}

ソケット/コンテキストを閉じて再度開く必要がありますか、それとも Jeromq ライブラリで処理する必要がありますか? おそらくTomcatはこれらをスローする可能性が高く、JULアペンダーで処理する必要がありますか?

ありがとう。

4

1 に答える 1

0

あなたの答えは、このスレッドでここにあるようです。#cafebabe は、その下のコメントで回答にさらに情報を追加しました。これにより、ここで質問に直接回答できます。

「アプリケーションがマルチスレッドの場合は、チャネルで IO 操作を実行しているスレッドを中断する可能性のある #interrupt() 呼び出しを探す必要があります。これが Web アプリケーションまたはその他の種類の管理された環境である場合、スレッド管理はアプリケーション (サーブレット/EJB コンテナーなど) に依存していない場合は、スレッド セーフ違反を探す必要があります。別の場所として、アプリケーションがシャットダウンしている場合や、スレッド プールが使用されている場合 (サーブレット/EJB コンテナー!) があります。次に、プール サイズの動的管理に注意してください!"

于 2013-11-20T21:47:48.603 に答える