Summary of the invention
The invention provides a kind of database interactive processing method and system, exist the more database that causes of concurrent program to hang up the no longer problem of response request in order to solve in the prior art.
The invention provides following technical scheme:
A kind of database interactive processing method may further comprise the steps:
Receive the request of accessing database from application layer;
Obtain concurrent number, described concurrent number is meant the maximum quantity that allows to handle simultaneously concurrent program;
Whether the quantity of judging the concurrent program of working as pre-treatment is less than described concurrent number, if, processes said request then, otherwise, the result who returns the refusal execution is to application layer, wherein processes said request may further comprise the steps: inquire about the corresponding relation of predetermined process time and concurrent number and obtain concurrent number again according to the mutual maximum duration of database in the concurrent program of pre-treatment, judge that further whether the quantity of the concurrent program of working as pre-treatment is less than the concurrent number that obtains again, if, then accept this request and carry out the corresponding database operation, otherwise rejecting said request.
Processes said request is meant to be accepted this request and carries out the corresponding database operation.
Also comprise step when accepting described request:
The start time and the concluding time of record concurrent program database interaction process, determine the time that the concurrent program database is mutual according to described start time and concluding time, and upgrade described averaging time.
Quantity according to mutual time of the database of each concurrent program of having carried out and the concurrent program carried out is upgraded described average handling time; Perhaps
According to the quantity and the described averaging time of mutual time of concurrent program database of this acquisition, the concurrent program before this, carried out, upgrade described averaging time.
Further also obtain concurrent number again according to the corresponding relation of inquiring about predetermined process time and concurrent number averaging time after upgrading.
Inquire about the corresponding relation of predetermined process time and concurrent number and determine described concurrent number according to the mutual maximum duration of database in the concurrent program of pre-treatment.
Acquiescence is accepted the request of first accessing database and is carried out the corresponding database operation.
A kind of database interaction process system comprises:
Application interface is used for receiving from application layer the request of accessing database;
Processing module is used to obtain concurrent number, and whether judges quantity when the concurrent program of pre-treatment less than described concurrent number, and described concurrent number is meant the maximum quantity that allows to handle simultaneously concurrent program;
Execution module, be used for when judged result processes said request when being, when judged result is not returned the result that refusal is carried out to application layer for the time, wherein when judged result when being, execution module is inquired about the corresponding relation of predetermined process time and concurrent number and is obtained concurrent number again according to the mutual maximum duration of database in the concurrent program of pre-treatment, judge that further whether the quantity of the concurrent program of working as pre-treatment is less than the concurrent number that obtains again, if, then accept this request and carry out the corresponding database operation, otherwise rejecting said request.
Beneficial effect of the present invention is as follows:
Whether 1, the present invention judges when each database access request comes, allow to carry out, and in real time database access is monitored; And when going wrong isolated data storehouse request of access automatically, avoided a large amount of request of access to cause system to hang up, needn't wait for analysis result.
2, the present invention can export various data at any time and monitors and analyze, and needn't wait for and just can analyze after outputing to the monitoring daily record.
3, the present invention monitored the mutual time of the database of concurrent program, and the concurrent number of further control permission, so the present invention is applicable to various Database Systems, and adopt the present invention to increase, also can be well controlled during the database performance variation in data volume.
Embodiment
Exist the more database that causes of concurrent program to hang up the no longer problem of response request in the prior art in order to solve, the present invention controls the quantity of concurrent processor in averaging time that the database key-course is handled according to concurrent program and the maximum duration carried out.
Referring to Fig. 1, database interaction process system comprises application interface 101, processing module 102, statistical module 103 and execution module 104 in the present embodiment.
Application interface 101 receives the request of accessing database from application layer.
Processing module 102 generates unique identification for each request, obtains the quantity of the concurrent program of concurrent number and current execution from statistical module 103, and whether the quantity of concurrent program of judging current execution is less than concurrent number.
Statistical module 103 is determined concurrent number according to the mutual maximum duration of database in the concurrent program of executed concurrent program average handling time or current execution, and adds up the quantity of the concurrent program of current execution.
Execution module 104 when judged result be less than the time processes said request, the execution concurrence program; When judged result is to return the information that refusal is handled to application layer when being not less than.
Referring to Fig. 2, the basic procedure of database interactive processing method is as follows in the present embodiment:
Step 201: receive request from the accessing database of application layer.
Step 202: obtain concurrent number, described concurrent number is meant the maximum quantity that allows to handle simultaneously concurrent program.
Step 203: whether judge quantity when the concurrent program of pre-treatment less than described concurrent number, if, processes said request then, otherwise, rejecting said request.
Referring to Fig. 3, the detailed process of database interactive processing method is as follows in the present embodiment:
Step 301: receive the request of accessing database, and for it generates unique identification, described request is generally a Structured Query Language (SQL) (SQL), comprises increase, deletes, revises and searches.
Sign is generally sequential encoding, can be numeral or letter or their combination, also can be SQL statement itself.This sign can be expressed the kind of request, can obtain the quantity of the concurrent program that executed finishes and the quantity of the concurrent program carried out by sign.Also can be for request like the category is provided with a sign, the described similar type that is meant request and required execution time are basic identical.
Can increase a gauge tap, select whether use this programme, select application scheme when needed, the flow process below continuing.
Step 302: obtain the average handling time (to call averaging time in the following text) of the concurrent program carried out, and determine current concurrent number according to the corresponding relation of averaging time and processing time and concurrent number.
Concurrent number is meant and allows the quantity of the concurrent program of execution at most simultaneously.Processing time is meant carries out in the execution concurrence program process the mutual time of database.
If so just there is not averaging time in first request, then giving tacit consent to averaging time is 0, perhaps directly allows to handle first request.
Step 303: whether the quantity of judging the current concurrent program of carrying out is less than current concurrent number, if then continue step 304, otherwise continue step 307.
Step 304: obtain the mutual maximum duration of database in each concurrent program of carrying out.
Step 305: whether the quantity of judging the current concurrent program of carrying out is less than the concurrent number that described maximum duration allowed, if then allow to handle this request, execution concurrence program, continuation step 306; Otherwise continue step 307.
General database manipulation is to finish in 1 second, and the maximum data storehouse linking number that general application server is provided with is about 25.The corresponding relation of averaging time and maximum duration and concurrent number is as follows in the present embodiment:
Time is 0 to 2s, and the concurrent number of permission is 5;
Time is 2 to 5s, and the concurrent number of permission is 3;
Time is 5 to 8s, and the concurrent number of permission is 2;
Time is more than the 8s, and the concurrent number of permission is 1.
Can adjust above-mentioned corresponding relation according to factors such as the type of database and data volumes.
Step 306: allow to handle this request, the time that begins to carry out that database of record is mutual, end of record (EOR) time when database finishes alternately, and the averaging time of upgrading the concurrent program of having carried out.Can also further upgrade concurrent number, then in step 302, can directly obtain concurrent number.
Also can be from the start and end time that monitoring be obtained concurrent program the daily record, but monitoring daily record at present read that to be limited to performance requirement generally be independent and non real-time, present embodiment is direct record in accessing database, this is a kind of preferable mode.Can also at any time various data (execution time of each concurrent program and current averaging time etc.) be outputed to monitoring analysis system, carry out instant analysis.
The various data of the concurrent program carried out are kept in the internal memory, only need be according to the current averaging time of Time Calculation of the sign of each request of writing down in the internal memory and averaging time that obtained last time and the execution of this concurrent program, so calculated amount is very little, and can obtain to be used for the averaging time that concurrent program quantity controls.
The aforementioned calculation method is a kind of preferable scheme, also can calculate current averaging time according to the processing time and the quantity of each concurrent program of having carried out.
Step 307: the result who returns the refusal execution is to application layer.
Referring to Fig. 4, the detailed process of another kind of database interactive processing method is as follows in the present embodiment:
Step 401: receive the request of accessing database, and for it generates unique identification, described request is generally a Structured Query Language (SQL), comprises increase, deletes, revises and searches.
Step 402: obtain the mutual maximum duration of database in each concurrent program of carrying out.
If the current program of not carrying out, then giving tacit consent to the execution time is 0, perhaps directly allows to handle first request of access.
Step 403: whether the quantity of judging the current concurrent program of carrying out is less than the concurrent number that described maximum duration allowed, if then continue step 404; Otherwise continue step 405.
General database manipulation is to finish in 1 second, and the maximum data storehouse linking number that general application server is provided with is about 25.The corresponding relation of maximum duration and concurrent number is as follows in the present embodiment:
Time is 0 to 2s, and the concurrent number of permission is 5;
Time is 2 to 5s, and the concurrent number of permission is 3;
Time is 5 to 8s, and the concurrent number of permission is 2;
Time is more than the 8s, and the concurrent number of permission is 1.
Can adjust above-mentioned corresponding relation according to factors such as the type of database and data volumes.
Step 404: accept this request, carry out associative operation to database.
Step 405: the result who returns the refusal execution is to application layer.
Whether the present invention judges when each database access request comes allow to carry out, in real time database access is monitored; And when going wrong isolated data storehouse request of access automatically, avoided a large amount of request of access to cause system to hang up, needn't wait for analysis result.The present invention can export various data at any time and monitor and analyze, and needn't wait for that outputing to monitoring just can analyze after the daily record.And, the present invention monitored the mutual time of the database of concurrent program, and further controlled the concurrent number that allows, so the present invention is applicable to various Database Systems, and adopt the present invention to increase, also can be well controlled during the database performance variation in data volume.
Obviously, those skilled in the art can carry out various changes and modification to the present invention and not break away from the spirit and scope of the present invention.Like this, if of the present invention these are revised and modification belongs within the scope of claim of the present invention and equivalent technologies thereof, then the present invention also is intended to comprise these changes and modification interior.