質問

私は私の手に興味深い状況を持っています。今数年間私たちはロギングに使用するネットワーク上のIISボックス上で実行されるWCFサービスを持っています。アプリケーションはBasichTtpBindingを使用してログメッセージを送信し、それらをデータベースにログに記録します。他のすべてのアプリケーションからのロギングのほとんどは、1回の操作ごとに数十桁のログに制限されています。最近、このロギングサービスを使用するように別のアプリケーションを移植しました。このアプリケーションは、ロギングサービスの他のクライアントよりもかなり積極的にログインします。コース中に100,000のメッセージを記録することができる操作があります(これはCSVファイルを介して10万レコードをインポートするためのものです)。

これをより効率的にする方法をより効率的に見つけようとして、アプリケーションがロギングサービスと直接通信するのではなく、ログ要求をキューに入れ、それらをサービスに転送することを試みることが提案されました(要求 がパフォーマンス目的で別のスレッドで送信されました)。このようにして、ログが書き込まれている間はアプリケーションはブロックされません。私は私の地元のマシン上のこのMSMQソリューションの概念の証明を実行しましたが、私が以前にMSMQを使用したことがないので、そして私がその場所が技術的に何があるかを学ぶだけであるので、私は多くの質問とほんの少数の答えを見つけています。 。私はMSMQがどのように機能するかについての簡潔な情報を誰かが私を指すことができることを願っています。

MSMQを実装した後に見ているもの:

  • ログを送信するアプリケーション MSMQはほぼすぐに戻ります (ログを待っているのではなく) 私が望むものであることを犯した。
  • 私は1000のログを送信したとしても 30未満のMSMQアプリケーション 秒数、それは数分かかります 1000のすべてのログを作成します データベース。それは私のように現れます キューにはある種のスロットルがあります それを保持している場所を有効にしました 要求を記録しますが、私はそれをチェックする方法はわかりません。
  • MSMQサービスからログを受信したサーバーでNet.tcpを使用している場合、私は1トンのサービスタイムアウトエラーを取得し、ログの90%(またはそれほど)わずか90%(またはso)だけをデータベースにしますが、BasichttpBindingを使用する場合確実に

    これは私のMSMQサービスのコードです:

    public void QueueLog(Log log)
    {
        try
        {
            ServiceClient writeLog = getLoggingService();
    
            string exceptionText = log.Exception == null ? string.Empty : log.Exception.ToString();
            writeLog.WriteCompatibleLog(log.LoggerName, (LoggingService.Logging.LogType)log.LogType, exceptionText, log.Message, log.ApplicationName, Utility.GetAssemblyVersion(Assembly.GetCallingAssembly()),
                Utility.GetFirstIPAddress(), Utility.GetHostName(), log.Category);
        }
        catch (Exception ex)
        {
            Debug.WriteLine("LoggingServiceWrapper.DotNet Error\n\n" + ex.GetBaseException().Message + "\n\n" + ex.GetBaseException().StackTrace);
        }
    }
    
    private ServiceClient getLoggingService()
    {
        return new ServiceClient(new BasicHttpBinding(), new EndpointAddress("http://MyServer/Service.svc"));
    
    }
    
    .

    ここにMSMQサービスを作成するコードが含まれています

    if (!MessageQueue.Exists(Properties.Settings.Default.QueueName))
    {
        MessageQueue.Create(Properties.Settings.Default.QueueName, true);
    }
    
    ServiceHost serviceHost = new ServiceHost(typeof(LoggingServiceQueue.LoggingServiceQueue), new Uri(Properties.Settings.Default.Address));
    {
        serviceHost.Open();
    
        Console.ReadLine();
    
        serviceHost.Close();
    }
    
    .

    これはMSMQサービスを呼び出すために使用するアプリケーション内のコードです。

    LoggingServiceQueueClient client = new LoggingServiceQueueClient(new NetMsmqBinding(NetMsmqSecurityMode.None), new EndpointAddress("net.msmq://localhost/private/Logging"));
    
    client.QueueLog(new LoggingServiceQueue.Log
    {
        LoggerName = loggerName,
        LogType = (LoggingServiceQueue.LogType)logType,
        ApplicationName = applicationName,
        Category = category,
        Exception = exception,
        Message = message,
        SourceHostName = Utility.GetHostName(),
        SourceIp = Utility.GetFirstIPAddress(),
        Version = Utility.GetAssemblyVersion(callingAssembly)
    });
    
    .

    誰かが提供できるのを助けています。 MSMQを使って私に利用可能な機能のセットを正確にどのようなものであるかについて少し失われています。私はGoogleを介して6営業時間の研究を行った。私が見つけたほとんどのドキュメントはかなり古い(2007)、そして厳しい読み物です。おそらく彼らは私が主題に関するいくつかのベースレベルの知識を持つことを期待しています。

役に立ちましたか?

解決

What you're seeing (if you're using net.msmq binding on your WCF) is what is designed to happen.

MSMQ, as a store-and-forward facility, will store messages in a queue at the sending client and the receiving server until either network or processing bandwidth is available. What this does is take load off the client (as you've observed) by making the process asynchronous.

You can view the statuses of the queues using Performance Monitor, the number of messages in the outbound queue (at the client) and the server queue are written to performance counters in realtime and can be viewed and/or logged.

If the performance is sub-optimal, you could look to change the WCF throttling settings to allow more concurrent connections in your service behaviour.

e.g.

<serviceThrottling
         maxConcurrentCalls="20"
         maxConcurrentSessions="20"
         maxConcurrentInstances="20"
       />

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top