Home > Net >  .net core standalone deployment application how to deal with a kind heart seconds kill steal a scene
.net core standalone deployment application how to deal with a kind heart seconds kill steal a scene

Time:12-10

Each, we use the.net 2.2 + MSSQL 2012 core web application development, because the project to be deployed to the client machine, cannot install redis, rabbitmq, the application has a order function, there may be thousands of users at the same time rob single situation, excuse me. Net core without other software, how to make the normal response to rob a single scene, there will not be no response, etc., trouble you glad! Thank you very much!

CodePudding user response:

Since it is to deal with the problem, why still tangle is single, he should be the server
If must be considered to be single, in fact, see your strategy
1, if you think is a can't be little, everyone must service, just respond to slowly, you can open the memory queue, memory cache, pool, slowly do
2, if you think I don't have to make sure everyone, anyway is to rob, to deal with, not to tell him that you didn't get the directly, this directly put the token bucket is good, have the token bucket, you eat, get a token bucket no token, directly go out, this means you directly refer to all kinds of so-called identity authentication interceptors and technologies, but the somebody else is authenticated, have permission into the into, have no access into the

CodePudding user response:

I found this project https://github.com/Zhangruyun/MemoryMessageQueue,
I call webapi interface implementation release information:
 await Task. Run (()=& gt; 
{
_queue. The Publish (" SalesOrderConsumer ", new SalesOrderMessage (DateTime. Now. The ToString ()));
});

But the interface point several times, the CPU is full, find the problem code is
https://github.com/Zhangruyun/MemoryMessageQueue/blob/master/MemoryQueue/MessageQueueHandler.cs
BindReceivedEvent method each time will be here a while loop
 while (! _queue. IsCompleted) 
{
If (_queue TryTake (out TMessage args))
_received (args, serviceFactory);
}

Can you tell me why want to use a while loop here, need not ok?

CodePudding user response:

If only single deployment, and cannot use redis similar kv storage system, but also moments of concurrency, although there are many restrictions, but it is not can't do,

Thinking:
Using System. Collections. Concurrent. ConcurrentBag Object
Pseudo code:
 
//assume storage for order ID identifies
Var cbList=new System. Collections. Concurrent. ConcurrentBag (a);
//put all need to grab the order data identification in the list (random disturb in order or put in advance are available)
CbList. Add (1);
CbList. Add (2);
//the current total cbList=2
//when the user list, take a returned to the client directly from queue
Int id;
if(! CbList. TryTake (out id))//this method can ensure thread safety, there will be no more than one user to the same order id
{
Return "error or queue is empty";
}
//take a later, the current total cbList=1
Console. WriteLine (id);//the current ids for customers to order id badge



Load-balanced across for multi-threaded use of objects, can ensure the safety of the thread, and under the single machine can greatly improve the concurrency value
  • Related