How do I set the socketTimeout in ktor? - kotlin

I tried
val socket = aSocket(ActorSelectorManager(Dispatchers.IO)).tcp().configure {
socketTimeout = 1000
}.connect("127.0.0.1", 2323)
I can set other values like this but not the timeout.
It's listed here TCPClientSocketOptions

The socketTimeout property is an extension of TCPClientSocketOptions as you said, but the scope from configure provides only SocketOptions. In order to correctly configure the TCP socket, you can specify the socketTimeout property when calling the connect function, like so:
val socket = aSocket(ActorSelectorManager(Dispatchers.IO))
.tcp()
.connect("127.0.0.1", 2323) {
socketTimeout = 1000
}

Related

How to increase max length of acceptable url for ktor?

Now I have ktor server is based on netty.
When I do to long GET request (about 9300 characters (mostly in query params)), ktor answers Unhandled: GET - /bad-request.
If I reduce length of url, it works fine.
In your embedded server config you can provide a function “httpServerCodec” to create HttpServerCodec (https://netty.io/4.1/api/io/netty/handler/codec/http/HttpServerCodec.html) in which you can set the maxInitialLineLength property.
embeddedServer(Netty, configure = {
// Size of the queue to store [ApplicationCall] instances that cannot be immediately processed
requestQueueLimit = 16
// Do not create separate call event group and reuse worker group for processing calls
shareWorkGroup = false
// User-provided function to configure Netty's [ServerBootstrap]
configureBootstrap = {
// ...
}
httpServerCodec = {
HttpServerCodec(.......)
}
// Timeout in seconds for sending responses to client
responseWriteTimeoutSeconds = 10
}) {
// ...
}.start(true)

Apache.NMS.ActiveMq ConnectionFactory ignores prefetch set in broker URL

This is the URL we're using to create/attach to our queue: tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=1
This defaults the queuePrefetch to 1000:
IConnectionFactory connectionFactory = new ConnectionFactory(queueServer);
connectionFactory = new SingleConnectionFactory(connectionFactory)
{
ReconnectOnException = true
};
If we use the following code it sets it appropriatly:
IConnectionFactory connectionFactory = new ConnectionFactory(queueServer)
{
PrefetchPolicy = new PrefetchPolicy{QueuePrefetch = 1}
};
connectionFactory = new SingleConnectionFactory(connectionFactory)
{
ReconnectOnException = true
};
Is there a reason ConnectionFactory is ignoring the prefetch we're setting in the URL? We tried setting the consumer.prefetchSize in the URL as well when connecting consumers and that seemed to do nothing.
The NMS library URI options would be prefixed with 'nms.' instead of 'jms.' which is the cause of your issue. So in your case you need to use:
nms.prefetchPolicy.queuePrefetch=1

Booksleeve setting expiration on multiple key/values

Unless I am missing something, I don't see a Multiple Set/Add overload that allows you to set multiple keys with an expiration.
var conn = new RedisConnection("server");
Dictionary<string,string> keyvals;
conn.Strings.Set(0,keyvals,expiration);
or even doing it with multiple operations
conn.Strings.Set(0,keyvals);
conn.Expire(keyvals.Keys,expiration);
No such redis operation exists - expire is not varadic. However, since the api is pipelined, just call the method multiple times. If you want to ensure absolute best performance, you can suspend eager socket flushing while you do this:
conn.SuspendFlush();
try {
foreach(...)
conn.Keys.Expire(...);
} finally {
conn.ResumeFlush();
}
Here is my approach:
var expireTime = ...
var batchOp = redisCache.CreateBatch();
foreach (...) {
batchOp.StringSetAsync(key, value, expireTime);
}
batchOp.Execute();

Sharepoint Client model - request timeout

I am receiving a timeout from the Sharepoint Client Managed Object model.
Microsoft.SharePoint.Client.ServerException: The operation has timed out.
Basically, I am batching 100 updates and sending them at one go. It is no problem for me if takes time but I really want to avoid timeout exception.
I have tried in a million of ways to increase the timeout in the client context but they were all without success. I have used reflection to try to identity what the sharepoint is doing when calling the executequery method of the client context. sharepoint is basically creating an HttpWebRequest and sending it.
I have ended with the below code, but still without success:
public static void SetInfinteTimeout(this ClientContext ctx)
{
int timeout = 10 * 60 * 1000;
ctx.RequestTimeout = timeout;
ctx.PendingRequest.RequestExecutor.RequestKeepAlive = false;
ctx.PendingRequest.RequestExecutor.WebRequest.KeepAlive = false;
ctx.PendingRequest.RequestExecutor.WebRequest.Timeout = timeout;
ctx.PendingRequest.RequestExecutor.WebRequest.ReadWriteTimeout = timeout;
System.Net.ServicePointManager.DefaultConnectionLimit = 200;
System.Net.ServicePointManager.MaxServicePointIdleTime = 2000;
System.Net.ServicePointManager.MaxServicePoints = 1000;
System.Net.ServicePointManager.SetTcpKeepAlive(false, 0, 0);
ServicePointManager.DnsRefreshTimeout = timeout; // 10 minutes
}
But I am still receiving a timeout error!
Is there anything else that I am missing please?
Any assistance would be greatly appreciated.
Have you tried
keeping default KeepAlive (true),
disabling Timeout and
keeping default MaxServicePointIdleTime value (which is 100 seconds by
default but you set to 2).
Just as:
public static void SetInfiniteTimeout(this ClientContext ctx)
{
ctx.RequestTimeout = -1; //ctx.RequestTimeout or System.Threading.Timeout.Infinite;
}
Also, how many seconds it takes for you to get timeout error, in your current configuration?
The solution was to use clientcallablesettings (SPWebApplication.ClientCallableSettings):
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.clientcallablesettings.aspx
This has an execution timeout property and other related settings.
In my case, I needed to add this in the Upgrade Actions as per the below code
using (SPSite site = new SPSite(siteURL))
using (SPWeb web = site.OpenWeb())
{
site.WebApplication.ClientCallableSettings.ExecutionTimeout = TimeSpan.FromMinutes(60);
site.WebApplication.ClientCallableSettings.MaxObjectPaths = 1000;
site.WebApplication.ClientCallableSettings.MaxResourcesPerRequest = 1000;
site.WebApplication.ClientCallableSettings.EnableStackTrace = true;
site.WebApplication.Update();
}

WCF: Why does passing in a remote endpoint fail?

The problem I am having connecting a wcf client application to a host running on a separate machine is documented in a question previously asked:
WCF: Why does passing in a remote endpoint fail?
However, the solution provided here says you need to use a SpnEndpointIdentity with an empty string. Since my code doesn't look anything like the case in the example I have referenced, I need to know what to do with the SpnEndpointIdentity object I have created.
I have a ChannelFactory upon which I call Create channel, passing in an EndpointAddress:
public override void InitialiseChannel()
{
SpnEndpointIdentity spnEndpointIdentity = new SpnEndpointIdentity("");
var address = new EndpointAddress(EndpointName);
Proxy = ChannelFactory.CreateChannel(address);
}
(NB: ChannelFactory is of type IChannelFactory, where T is the service contract interface)
So what do I do with spnEndpointIdentity? I can't pass it to CreateChannel.
Or perhaps I can use it somehow when I create the channel factory:
private ChannelFactory<T> CreateChannelFactory()
{
var binding = new NetTcpBinding
{
ReaderQuotas = { MaxArrayLength = 2147483647 },
MaxReceivedMessageSize = 2147483647
};
SpnEndpointIdentity spnEndpointIdentity = new SpnEndpointIdentity("");
var channelFactory = new ChannelFactory<T>(binding);
return channelFactory;
}
Again, I can't pass it into the constructor, so what do I do with it?
Thanks.
You almiost got it.
What you're missing is that you associate the EndpointIdentity with the EndpointAddress, and then provide that to CreateChannel():
SpnEndpointIdentity spnEndpointIdentity = new SpnEndpointIdentity("");
var address = new EndpointAddress(EndpointName, spnEndpointIdentity);