Good morning, I'm developing a site to run in local intranet format on IIS
. With asp.net ADO
technologies in the WebForms
format, I'm using the SignalR
library to monitor a simple table in SQL Server Express
via SqlDependency
, which shows clients as real-time notifications equal to the top of the stackoverflow site. The users are authenticated in the site via authentication Forms
, the implementation is functional but when the site is started it will be slow and slow until the locking. I imagine that the flow of calls to the bank is congesting the network / IIS. Look at the implementation code, if anyone can point out what is causing the slowness.
Hub class:
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace ZaniADV
{
[HubName("MyHub")]
public class MyHub : Hub
{
public static void Show()
{
IHubContext context =
GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.All.displayStatus();
}
}
}
Statup class:
using Microsoft.Owin;
using Owin;
using Microsoft.AspNet.SignalR;
[assembly: OwinStartup(typeof(ZaniADV.Startup))]
namespace ZaniADV
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
GlobalHost.Configuration.DefaultMessageBufferSize = 500;
app.MapSignalR();
}
}
}
Global.asax
namespace ZaniADV
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
SqlDependency.Start(ConfigurationManager.ConnectionStrings
["MyConnectionString"].ConnectionString);
}
protected void Application_End()
{
SqlDependency.Stop(ConfigurationManager.ConnectionStrings
["MyConnectionString"].ConnectionString);
}
}
}
Code-Behind page MenuNotification.aspx.cs
[WebMethod]
public static IEnumerable<Inbox> GetData()
{
using (var connection = new SqlConnection
(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
{
connection.Open();
using (var command = new SqlCommand(@"SELECT [IndexID],
[Numero] FROM [AdvogadoDB].[dbo].[IndexA] WHERE [AdvogadoID] =" +
AdvogadoCRUD.ReturnAdvogadoID((Guid)Membership.GetUser().ProviderUserKey),
connection))
{
command.Notification = null;
SqlDependency.Start(
ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
if (connection.State == System.Data.ConnectionState.Closed)
connection.Open();
using (var reader = command.ExecuteReader())
return reader.Cast<IDataRecord>()
.Select(x => new Inbox()
{
Numero = x.GetInt32(1),
}).ToList();
}
}
}
private static void dependency_OnChange(
object sender, SqlNotificationEventArgs e)
{
MyHub.Show();
}
}
}
Customer javascript code page MenuNotification.aspx:
<script src="Scripts/jquery-3.1.1.min.js"></script>
<script src="Scripts/jquery.signalR-2.2.2.js"></script>
<script src='<%= ResolveClientUrl("~/signalr/hubs") %>'></script>
<script type="text/javascript">
$(function () {
var job = $.connection.MyHub;
job.client.displayStatus = function () {
getData();
};
$.connection.hub.start();
getData();
});
function getData() {
var $inbox = $('#inbox');
$.ajax({
url: 'MenuNotification.aspx/GetData',
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
success: function (data) {
//debugger;
if (data.d.length > 0) {
$inbox.empty();
var newdata = data.d;
var rows = [];
for (var i = 0; i < newdata.length; i++) {
rows.push(newdata[i].Numero);
}
$inbox.append(rows.join(''));
}
}
});
}
</script>
<li class="dropdown tasks-menu"
data-toggle="tooltip" data-placement="bottom"
title="Últimas mensagens no inbox">
<a href="/ZaniADV/Views/Designar.aspx" target="_parent"
class="dropdown-toggle" data-toggle="dropdown">
<img src="/ZaniADV/Image/inbox.png" />
<label id="inbox" class="label label-danger"
style="font-size: 12px"></label>
</a>
</li>
Table BD:
ALTERDATABASEAdvocateBDSETENABLE_BROKER
Finalresult:
Client1:
Client2:
ResourceMonitor:
Memory:
CPU:
Network: