Claudiu
Claudiu

Reputation: 165

Synchronised requests enforced from ServiceStack 3 configuration

I have an ASP.NET application, using NGINX as a server and Servicestack 3.

When it comes to PUT requests, I'd like them to be synchronously processed as they come in to Servicestack from the NGINX server (never have multiple requests processed at the same time, since this could lead to them finishing their job in a different order from the one they were called in). As I understand it, it's possible to control the number of threads being used for incoming requests - If I'd be able to restrict that number to 1, I imagine I'd get the result that I want.

How would I go about achieving this from the level of ServiceStack configuration (if it's even possible - the accepted response from this question is making me think it isn't; but then if that's true, how am I supposed to enforce synchronisation)?

Upvotes: 1

Views: 163

Answers (1)

mythz
mythz

Reputation: 143359

It's unlikely you want to block the whole HTTP Server, that could cause all other requests to fail.

Have you just tried using a singleton lock? e.g. you could use the Type of your Service for this:

lock (typeof(MyService))
{
}

But locking in a Web Server like this is generally a bad idea, you should think of using some kind of optimistic concurrency control where it throws an error when trying to update a stale record. e.g. In OrmLite you can use its RowVersion feature for optimistic concurrency where clients send the RowVersion which represents the state of the record they have and if it's been updated since OrmLite will throw a OptimisticConcurrencyException which in ServiceStack automatically gets converted to a 409 Conflict HTTP Error Response.

Upvotes: 2

Related Questions