Skip to content

Commit

Permalink
Disables Proxy-using to improve HttpWebRequest performance
Browse files Browse the repository at this point in the history
  • Loading branch information
nthachus committed Jun 3, 2013
1 parent 26d5077 commit 5c5ea93
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
30 changes: 30 additions & 0 deletions CometD.NET/Client/Transport/LongPollingRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,37 @@ private static void GetResponseCallback(IAsyncResult asyncResult)
}

if (null != exchange._listener)
{
// Fixes the received messages before processing
string requestChannel = null;
string requestUrl, baseUrl;
foreach (IMutableMessage msg in messages)
{
if (String.IsNullOrEmpty(msg.Channel))
{
if (null == requestChannel)
{
requestUrl = exchange._request.RequestUri.ToString();// Absolute request URI

baseUrl = exchange._transport.Url;
baseUrl = (null == baseUrl) ? String.Empty : baseUrl.Trim();

if (requestUrl.StartsWith(baseUrl, StringComparison.OrdinalIgnoreCase))
{
requestChannel = requestUrl.Substring(baseUrl.Length).Trim('\\', '/');
requestChannel = Channel.Meta.TrimEnd('\\', '/') + "/" + requestChannel;
}
else
requestChannel = String.Empty;
}

if (!String.IsNullOrEmpty(requestChannel))
msg.Channel = requestChannel;
}
}

exchange._listener.OnMessages(messages);
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions CometD.NET/Client/Transport/LongPollingTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public override void Send(ITransportListener listener, params IMutableMessage[]
request.AllowWriteStreamBuffering = true; // Is needed for KeepAlive
request.AllowAutoRedirect = true;
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.Proxy = null; // Skips the proxy auto-detect step (~ 7s)

// Setups HTTP request headers
this.ApplyRequestHeaders(request);
Expand Down
6 changes: 6 additions & 0 deletions Salesforce.StreamingAPI/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,10 @@
]' />

</appSettings>

<system.net>
<connectionManagement>
<add address="*" maxconnection="32768" />
</connectionManagement>
</system.net>
</configuration>
28 changes: 15 additions & 13 deletions Salesforce.StreamingAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static void Main(/*string[] args*/)
AppDomain.CurrentDomain.UnhandledException += OnCurrentDomainUnhandledException;
// Set server certificate validation callback
ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteServerCertificate;
ServicePointManager.Expect100Continue = false; // TODO: Turning HttpWebRequest performance

IList<TestAccount> accounts = TestAccounts;
if (null != accounts && accounts.Count > 0)
Expand All @@ -38,24 +39,25 @@ static void Main(/*string[] args*/)
IStreamingAPIClient streamingClient = new StreamingAPIClient(account.UserName, account.Password);

Console.WriteLine("Handshake with client: {0}", account.UserName);
if (streamingClient.Handshake(60000))// 60 seconds timeout
/*if (*/
streamingClient.Handshake(60000);// 60 seconds timeout
//{
foreach (string topicName in account.PushTopics)
{
foreach (string topicName in account.PushTopics)
Console.WriteLine("Subscribes push-topic: {0} with listener2", topicName);
streamingClient.SubscribeTopic(topicName,
new CallbackMessageListener<IStreamingAPIClient>(OnMessageReceived2, streamingClient));

if (account.PushTopics.Count < 2)
{
Console.WriteLine("Subscribes push-topic: {0} with listener2", topicName);
Console.WriteLine("Subscribes push-topic: {0} with listener1", topicName);
streamingClient.SubscribeTopic(topicName,
new CallbackMessageListener<IStreamingAPIClient>(OnMessageReceived2, streamingClient));

if (account.PushTopics.Count < 2)
{
Console.WriteLine("Subscribes push-topic: {0} with listener1", topicName);
streamingClient.SubscribeTopic(topicName,
new CallbackMessageListener<IStreamingAPIClient>(OnMessageReceived, streamingClient));
}
new CallbackMessageListener<IStreamingAPIClient>(OnMessageReceived, streamingClient));
}

streamingClients[account] = streamingClient;
}

streamingClients[account] = streamingClient;
//}
}

Console.WriteLine("Press Enter to exit...");
Expand Down
1 change: 1 addition & 0 deletions Salesforce.StreamingAPI/StreamingAPIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private static void InitHttpRequest(HttpWebRequest req, string accessToken)
req.AllowWriteStreamBuffering = true; // Is needed for KeepAlive
req.AllowAutoRedirect = true;
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
req.Proxy = null; // Skips the proxy auto-detect step (~ 7s)

if (null != accessToken && (accessToken = accessToken.Trim()).Length > 0)
req.Headers[HttpRequestHeader.Authorization] = "OAuth " + accessToken;
Expand Down

0 comments on commit 5c5ea93

Please sign in to comment.