SCM

[#1010924] Server notifications lost when using asynchronous notification polling

View Trackers | Bugs | Download .csv | Monitor

Date:
2010-10-05 15:29
Priority:
3
State:
Open
Submitted by:
James Gregory (npgsqluser)
Assigned to:
Nobody (None)
Npgsql Version:
2.0.10
Category:
Group:
Resolution:
None
Summary:
Server notifications lost when using asynchronous notification polling

Detailed description
Hi,

We are using Npgsql to receive events based on notifications sent by a database server running PostgreSQL 9.0.0. The events are received asynchronously by polling the server intermittently via empty commands.

However, when stress testing this mechanism we have noticed that notifications are lost without any exceptions being raised or any other errors being reported. This can be seen by the simple example below which takes the form of two small test programs. One is used to connect to a server and issue commands which raise notifications. The other is used to connect to the server and listen to such notifications. In the example 5000 notifications are raised but it is often the case that the listener program fails to receive all 5000 notifications (sometimes we are lucky enough to receive all notifications, the example program may need to be run a few times to see the problem). The listener program logs it's activities to a simple text log so that missing notifications can be identified.

We would be grateful if you able to offer any help regarding this matter.

Kind regards,

James


--------------------------------------------------------
Example program which raises notifications in the server
--------------------------------------------------------

using Npgsql;

namespace NotificationTestNotifier
{
class NotifierProgram
{
public static void Main(string[] args)
{
var connStr = new NpgsqlConnectionStringBuilder()
{
Host = "writeHostNameHere",
UserName = "writeUserNameHere",
Password = "writePasswordHere"
};
var conn = new NpgsqlConnection(connStr.ToString());
conn.Open();

for (int sendNotifyCounter = 1; (sendNotifyCounter <= 5000); sendNotifyCounter++)
{
string commandStr = "SELECT pg_notify('notifytest', '" + sendNotifyCounter + "');";
NpgsqlCommand command = new NpgsqlCommand(commandStr, conn);
command.ExecuteNonQuery();
}

}
}
}

--------------------------------------------------------


--------------------------------------------------------------
Example program which listens to notifications from the server
--------------------------------------------------------------

using System;
using Npgsql;

namespace NotificationTestListener
{
class ListenerProgram
{
public static void Main(string[] args)
{
receiveNotifyCounter_ = 0;
sw_ = new System.IO.StreamWriter("NotifyTestListenerLog.txt");

var connStr = new NpgsqlConnectionStringBuilder()
{
Host = "writeHostNameHere",
UserName = "writeUserNameHere",
Password = "writePasswordHere"
};
var conn = new NpgsqlConnection(connStr.ToString());
conn.Open();

NpgsqlCommand command = new NpgsqlCommand("listen notifytest;", conn);
command.ExecuteNonQuery();

conn.Notification += new NotificationEventHandler(NotificationSupportHelper);

while (true)
{
command = new NpgsqlCommand(";", conn);
command.ExecuteNonQuery();
System.Threading.Thread.Sleep(1000);
Console.WriteLine(receiveNotifyCounter_);
sw_.Flush();
}

}

private static void NotificationSupportHelper(Object sender, NpgsqlNotificationEventArgs args)
{
receiveNotifyCounter_++;
int counterDiff = Convert.ToInt32(args.AdditionalInformation) - receiveNotifyCounter_;
lock (logLock_)
{
sw_.WriteLine("RNC = \t" + receiveNotifyCounter_ + ";\t SNC = \t" + args.AdditionalInformation + ";\t Diff = \t" + counterDiff);
}
}

static private int receiveNotifyCounter_ { get; set; }

static System.IO.StreamWriter sw_;
static object logLock_ = new object();
}
}

--------------------------------------------------------------

Followup

Message
Date: 2011-12-22 15:31
Sender: Francisco Figueiredo jr.

Sorry, Alexander....

I'll work on it and see what I get.
Date: 2011-12-22 08:11
Sender: Alexander Golikov

2Francisco Figueiredo jr.
Still no luck in this issue?
Date: 2011-01-02 16:06
Sender: Francisco Figueiredo jr.


Hi! I started to make the tests and also could confirm the notifications aren't being delivered correctly. I'll check that.
Date: 2010-12-03 08:40
Sender: Alexander Golikov

Confirmed.
I investigate this issue here:
http://pgfoundry.org/forum/forum.php?thread_id=2952&forum_id=519

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge