Home > Net >  Small white about "message queue" handle "kill" doubts!
Small white about "message queue" handle "kill" doubts!

Time:09-18

Recently in the message queue, some not understand place, hope to get your answer, thank you,
Each big web site wrote above message queue, there is a said that can handle down the business, such as database 10 items, there are 100 requests to come over, first put the request in queue, and then take a queue and take 10 requests, and then to the database, please strives for realism the column chart below (ali cloud copy)

The original address: http://www.cnblogs.com/linjiqin/p/5720865.html

"The request into the queue," once I thought, "queue" this stuff, you can save a "HTTP requests", program into the queue to take, or to take out a "HTTP requests", then the request can be returned to the client, I tried Microsoft MSMQ today, simple to use, like a queue can only put the string, I received, that if it is, that how to deal with the seconds kill??

Asked some people behind, said that the queue is put the requested data, not a "request",

Just seconds kill the example above, here are the questions:
1, queue to store the data, if I am a HTTP request sent, the server to request data into the queue, and then I will release the returned to the client request? What is the client status or performance? Waiting for?
2, I only have 10 commodity database, I put all requested data in the queue, the queue how to inform my program, notice he can start to pick up the inside of the queue data?
3, I took the data in the program from the queue, handle good, I how to inform front waiting for interface, display the results??



Beg you experienced a great god, help me to analyze these details, thank you!


CodePudding user response:

There is no order, I try,

CodePudding user response:

The building Lord have the idea

CodePudding user response:

Write a console demo for you
 using System; 
using System.Threading.Tasks;

The namespace ConsoleApp1
{
Class Program
{

The static void Main (string [] args)
{
for (var i=0; i <30; I++)
The Test (I);
Console. WriteLine ("... Press any key to end ");
Console.ReadKey();
}

Static int the execution of the number;
The static object lockflag=new object ();
The static event Action A task over;

The static async void Test (int I)
{
The lock (lockflag)
{
If (execution of quantity & gt;
=3){
Action Proc=null;
Proc=new Action (x=& gt;
{
A task end -=proc;
The Test (I);
});
A task end +=proc;
return;
}
The else
Perform number + +;
}
Var r=await plus 100000 (I);
Console. WriteLine ($" output: input: {I}, {r} ");
The lock (lockflag)
{
Console. WriteLine ($" -- -- -- -- -- -- -- -- input: {I} after the end of the execution of quantity for: number} {the execution of ");
The execution of Numbers,;
}
If (a task over!=null)
Task over (I);
}

The static Random RND=new Random ();

The static async Task 100000 (int x)
{
Var d=RND. Next (3000, 5000);
Await Task. Delay (d);//simulation time consuming operations
Return x + 100000;
}

}
}


Here, assume that the task is to put the I of input and output 100000, the main program launched 30 concurrent tasks quickly, but this Test methods required to perform three tasks at the same time, most of the other waiting in line, you can run this example, and answer your own question:

When produced after concurrent tasks, the first to enter the first lock management area, at this time to judge if the number of concurrent tasks run & gt;=3, queue to event listeners registered listening, then immediately over, when the event occurs (end of the other tasks), from the event queue cancellation listening first, and then re-execute this task (start to judge whether the number of concurrent tasks & gt;=3), otherwise, it will immediately put the number of concurrent tasks + +, pay attention to the two actions are in lock management scope, at the same time there is only one thread to execute the code in that range, so it will not create chaos control,

15 or 20 years ago, like the Java language primitive, far more than the original. The net more primitive, all of a heap of rubbish Java books are copied from 30 years ago, c, 40 years ago, Unix some concept on the books, the so-called "queue" is a relatively easy to debase the concept, many seem to use the word "queue" to their gold, and in fact still order block train of thought, the books of inefficient, "queue" is the runtime code trival things, so the key here is to use pure code, with elegant. Net mechanism to write efficient code, so you ask a few questions is very good, you don't tangle "queue" the word but ask on the key details!

CodePudding user response:

Let's take a look at the real in the.net on this program should be how to write the
 using System; 
using System.Threading.Tasks;

The namespace ConsoleApp1
{
Class Program
{

The static void Main (string [] args)
{
for (var i=0; i <30; I++)
The Test (I);
Console. WriteLine ("... Press any key to end ");
Console.ReadKey();
}

The static async void Test (int I)
{
Var r=await plus 100000 (I);
Console. WriteLine ($" output: input: {I}, {r} ");
}

The static Random RND=new Random ();

The static async Task 100000 (int x)
{
Var d=RND. Next (3000, 5000);
Await Task. Delay (d);//simulation time consuming operations
Return x + 100000;
}

}
}

Because the.net thread pool system will automatically according to the current system resources situation and scheduling - delay - concurrent tasks, so you don't need to write their own code of what control tasks, without what "queue", because the net system thread pool is in itself a queue, and it is the thread state object needed to perform a task in memory data maintained (don't need any "string),

So, in fact, no to what "queue", in the thread pool on the net you use involves the system of high-level framework (e.g., PLinq) to programming, you basically don't have to consider what the queue, tangle queue when we can be regarded as a Java programmer or some c language for beginners, these people will be particularly like the concept of the underlying,

CodePudding user response:

I say first above their management control mechanism of "queue", and that as a.net programmers are basically does not consider the queue, then the final answer is, in fact, some people say another "queue" is not really a queue, but the somebody else Microsoft (or IBM, etc.) of the development of the past communication gateway program, the somebody else to allow a string (such as a the.net object json serialization of results) from one machine to another machine, read the string target machine order,

Your target machine to read the data, then, as I wrote above the Test (I), but you is to perform "parsing string (STR)" to determine the json isn't a task description, if it is processed it is time-consuming, so at this time of the so-called "queue" is actually refers to a mature for string has released "flow" of the communication gateway framework (such as MSMQ) concept, this time is even more need to awake, don't entangled with what "queue" concept!

CodePudding user response:

Business logic is actually is: users began to kill, if the server processes the request too much now, will he go to the error page, don't kill the business logic of the processing seconds,
Solve the problem should be: when a user visits when possible the breakdown, or concurrency issues, such as only 30 goods, sell 31 result, stock of 1,
The paper says the queue only "processing request too much" a means to this logic,
As to this method is good, I've never used, no comment,

CodePudding user response:

, for example, there are 20 kinds of products, a total of 100000 seconds to kill the goods, then you will at best to row to 100000 after the user requests to say "no treatment", do not casually for the number of physical machines according to your own imagination does not handle seconds kill the business logic,

CodePudding user response:

Own imagine the number of physical machines - & gt; Your own imagination of the internal resource of physical machines quantity

Internal resources is a comprehensive index, so the author of a few decades ago can only use a poor "concurrency" their way to control the indicators, but also static, and the net system thread pool can thread scheduling dynamic management, at the beginning will be delayed a little time to avoid start too many tasks at the same time, so usually need not invented what queue mechanism,

CodePudding user response:

Seconds kill, no inventory reduction,

Seconds kill 100000 pieces of goods, for example, then put the item in the memory, each take a seconds kill request to lose an item, but the whole management information system, the inventory account, that is to reduce after, perhaps even for 20 seconds or 20 minutes, the user has been navigation to pay even delivery link - after processing,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related