CN104731655B - The sustainable operation method and system of script - Google Patents

The sustainable operation method and system of script Download PDF

Info

Publication number
CN104731655B
CN104731655B CN201510160037.5A CN201510160037A CN104731655B CN 104731655 B CN104731655 B CN 104731655B CN 201510160037 A CN201510160037 A CN 201510160037A CN 104731655 B CN104731655 B CN 104731655B
Authority
CN
China
Prior art keywords
time
script
service logic
perform
execution
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510160037.5A
Other languages
Chinese (zh)
Other versions
CN104731655A (en
Inventor
梅存兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing Tu Niu Science And Technology Ltd
Original Assignee
Nanjing Tu Niu Science And Technology Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing Tu Niu Science And Technology Ltd filed Critical Nanjing Tu Niu Science And Technology Ltd
Priority to CN201510160037.5A priority Critical patent/CN104731655B/en
Publication of CN104731655A publication Critical patent/CN104731655A/en
Application granted granted Critical
Publication of CN104731655B publication Critical patent/CN104731655B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention discloses a kind of sustainable operation method of script and the runtime that can realize this method, method includes:Start by set date script;It is loaded into configuration;Check complications;Circulation performs service logic within the time of license;System includes timing starter, configuration module, con current control module, execution time control module.Avoid script concurrent, the execution time is short, can reach the response of second level, reduce maintenance cost.The present invention can realize the operation that is repeated cyclically of script, and script periodically can restart and terminate automatically, so as to realize the Dynamical Deployment of code, without manual intervention, reduce maintenance cost;And can be to script the execution time accurately managed, time precision is high, can reach below second level.

Description

The sustainable operation method and system of script
Technical field
The invention belongs to software technology field, and in particular to a kind of to make the method for page script continuous service and be System.
Background technology
Script is traditional to write-compiling-in order to shorten and link-running and the computer programming language that creates Speech, applied to the at all levels of computer system, has especially obtained extensive utilization in webpage development field.At present, network application Increasingly abundanter, the use of webpage and visual effect be unable to do without the script embedded in webpage.Conventional script has JavaScript, ASP, PHP, python, perl, ruby etc..
By taking PHP language as an example, in web site architecture, it will usually after writing one section of shell script using PHP, make its timing rear Platform is run, and is commonly called as timing script, timed task.Timed task is commonly used to perform regularly task, such as daily morning zero point is clear Manage daily record, the report of 8 points of transmission proxima luce (prox. luc)s every morning.There is a kind of timed task to be desirable to what is continuously run without interruption, such as Short message sending status renewal, electronic fax send state renewal, pay status renewal.By taking pay status as an example, guest initiates branch After the task of paying enters Third-party payment platform, it is necessary to open a timed task and check pay status, so as to prop up as far as possible Pay more new state in the successful shortest time.But script single be present and perform overlong time in existing timing script execution, The response of second level is unable to reach, it is necessary to the problems such as manual intervention, maintenance cost height.
The content of the invention
To solve the above problems, the invention discloses a kind of sustainable operation method of script and this method can be realized Runtime, avoid script concurrent, the execution time is short, can reach the response of second level, reduce maintenance cost.
In order to achieve the above object, the present invention provides following technical scheme:
The sustainable operation method of script, comprises the following steps:
Step A, script is periodically started using timing starter;
Step B, prevent complications from producing by locking file:
Step B-1, check that lock file whether there is, when in the absence of lock file, create lock file and perform step C;When During in the presence of lock file, step B-2 is performed;
Step B-2, periodically reexamine lock file and whether there is, if allowing original existing lock text in the time waiting Part is deleted and then creates new lock file, and performs step C;If original existing lock file is still within the wait permission time In the presence of then execution step B-3;
Step B-3, lock file is checked from being created to whether the current time exceeds schedule time, if it exceeds during regulation Between, then delete original existing lock file and create new lock file;If being no more than the stipulated time, terminate script operation;
Step C, the circulation execution service logic within the whole PHP scripts single maximum executable time, and according to single industry The time and total execution duration management business logic of script that actual execution duration, the service logic single of business logic can perform Execution number;
Step D, delete lock file.
Further, the step C comprises the following steps:
Step C-1, perform service logic call back function;
Step C-2, the execution duration of service logic is calculated,
Step C-3, the remaining execution duration of script is calculated, held when residue is performed when duration performs service logic next time enough Row step C-4, otherwise terminate to perform;
Step C-4, when being less than the time that service logic single can perform the time of the actual execution of service logic once, Step C-5 is performed, otherwise performs step C-1;
Step C-5, pause a period of time, until after this execution duration is equal to the time that service logic single can perform Perform C-1.
Further, the time that the service logic single can perform=whole PHP scripts single maximum executable time The readjustment frequency n of service logic in one life cycle of t/PHP scripts, the t and n are pre-configured with and in step A perform scripts After load.
Further, total execution duration of the script is equal with the start by set date cycle of script.
Present invention also offers the runtime that can realize above-mentioned script sustainable operation method, including start by set date Device, configuration module, con current control module, execution time control module;Wherein timing starter can periodically start script, match somebody with somebody Put module and be used to configure service logic in maximum one life cycle of executable time and PHP scripts of whole PHP scripts single Adjust back number;Con current control module prevents complications from producing by checking, creating or deleting lock file;Perform time control mould Block is used for the circulation within the whole PHP scripts single maximum executable time and performs service logic, and according to single service logic The execution time of the actual total execution duration management business logic for performing duration, the time that service logic single can perform and script Number.
Compared with prior art, the invention has the advantages that and beneficial effect:
1. the operation that is repeated cyclically of script can be realized, script periodically can restart and terminate automatically, so as to reality The Dynamical Deployment of modern code, without manual intervention, reduce maintenance cost.
2. the execution time of pair script is accurately managed, time precision is high, can reach below second level.
3. eliminating, PHP scripts are concurrent, avoid the resource concurrently brought fight for, result Unpredictability.
4. system complexity is reduced, the problems such as avoiding RAM leakage, the resource deadlock that PHP code longtime running is brought, The strong point of PHP language is played.
Brief description of the drawings
Fig. 1 is the sustainable operation method and step flow chart of script provided by the invention;
Fig. 2 is step B control flow charts;
Fig. 3 is step C control flow charts.
Embodiment
Technical scheme provided by the invention is described in detail below with reference to specific embodiment, it should be understood that following specific Embodiment is only illustrative of the invention and is not intended to limit the scope of the invention.
The invention provides a kind of sustainable operation method of script and corresponding system, following for script can be realized Ring continuous service, and many disadvantages of the prior art are overcome, it will be described in detail below by taking PHP scripts as an example.Operation System mainly includes following four module:Timing starter, configuration module, con current control module, execution time control module, it is fixed When starter be used for start by set date script, configuration module is used to configure relevant parameter, and con current control module is used to create and delete File is locked, and by preventing same script from concurrently performing the inspection for locking file, performs time control module and is held for circulation The execution frequency of row service logic and management business logic.Method flow provided by the invention is as shown in figure 1, including following step Suddenly:
Step A, script is periodically started using timing starter.We can use the timer of operating system, such as Linux crontab, it so can periodically start PHP scripts, such as:We set opening for PHP scripts in crontab Dynamic frequency, it is per minute to start 1 time.Timing restart script makes PHP code no longer need for a long time perform, when we set it is per minute When restarting one time, as long as the execution time of a PHP script reaches one minute, it is not necessary to running down year in year out.This Outside, restart once automatically because script is per minute, and PHP code can update at any time, after fresh code issue, it is not necessary to Manually restart PHP processes, to when starting PHP scripts next time, carry out newly deployed code, reached and " performed in script During upgrade software, and without restarting system " effect.
In perform script, it is also necessary to carry out con current control and time control, this just needs first to configure two crucial ginsengs Number --- whole PHP scripts single maximum executable time t(Acquiescence 1 minute), service logic in one life cycle of PHP scripts Readjustment frequency n(Typically not greater than 60 times)And the call back function of service logic.Meanwhile time of application claims service logic Function timing is adjusted to be less than t/n.These above-mentioned parameters and call back function are configured in configuration module, are starting script Configuration is loaded into afterwards.
Step B, con current control module is performed, prevent complications from producing by checking, creating or deleting lock file.This step Rapid control flow is as shown in Fig. 2 mainly comprise the following steps:
The title of generation lock file, check that lock file whether there is, when in the absence of lock file, create lock file and perform Subsequent step;When lock file being present, also periodically reexamining lock file and whether there is, if allowed waiting in the time, Original existing lock file, which is deleted, then creates new lock file, and performs subsequent step;It is former if allowed waiting in the time There is existing lock file still to exist and then check lock file from being created to whether the current time exceeds schedule time, if it exceeds Stipulated time, then delete original existing lock file and create new lock file;If being no more than the stipulated time, terminate script Operation.
This example, which will wait, allows the time to be set to t/3, and the time for periodically reexamining lock file is set to inspection per second once, rule Fix time and be set to 3t, be attached to variety of problems that may be present when script performs, enumerate several feelings that may be present in stepb Condition:
Normal scene:After script startup, check in the absence of lock file, at this moment create lock file, and perform subsequent logic (Step C), lock file is deleted after having performed, terminates script and performs.
Wait scene:After script startup, check in the presence of lock file, reexamine once each second;T/3 (three/ One t) in the time, and the script that old lock file is created lock file is deleted, and now creates new lock file, and perform and subsequently patrol Volume, lock file is deleted after having performed, terminates script and performs.This situation is held for the last time in the script that last creates lock Time-consuming remote super second from the bottom time of row service logic, which performs, takes what is just occurred.It is desirable that last script terminates to hold as early as possible Row is so a script terminates in wait;But if a upper script does not terminate the wait after so this startup undoubtedly for a long time It is in consumption server resource, it is contemplated that in the case of the accidental exception of server, most of service logic is can be in t/3 Terminate processing, therefore we take suitable waits to allow time value t/3, will not consume excessive server resource.
Etc. scene to be interrupted:After script startup, check in the presence of lock file, reexamine once each second;Just above During the t/3 times, old lock file still has, and check lock file from be created to the now time no more than 3t (three times T), terminate script to perform.
Scene four:Wait and continue scene, after script startup, check in the presence of lock file, reexamine once each second; During to just above the t/3 times, old lock file still has, and checks lock file from the now time is created to more than 3t (three T again), old lock file is deleted, creates new lock file, performs subsequent logic(Perform time control module), delete lock text Part, terminate.When last time service logic is because of resource link time-out(Such as database connection time-out, socket time-out)Can not When continuing executing with, if more than we set it is of long duration be no longer waiting for previous script but delete lock file after start to perform Service logic in current script.
It should be noted that above-mentioned wait allows time and stipulated time to be adjusted as needed, and reach as far as possible Following effect:When slight abnormality occurs in server, reduce wasted caused by waiting as far as possible, increase service logic as far as possible Perform number;When great exception occurs in server and recovers, it can voluntarily recover script and run without manual intervention.
Lock file in con current control module, the filename of file is locked, by carrying out md5 to the complete trails of script file To realize uniqueness, lock file is stored under the catalogue specified, such as under linux /tmp/php/script/lock/ mesh Record, the content for locking file is the timestamp of precision to millisecond, and the time of file generated is locked in storage.Under ideal case, lock file exists Create during script startup, deleted at the end of script.When deleting lock file, we use the destructor function of class in PHP language. In PHP language, the destructor function of class is bound to call at the end of PHP scripts perform, and so ensures that PHP scripts itself go out Also lock file can be deleted when having showed code exception, does not influence to run next time.
Step C, the circulation execution service logic within the whole PHP scripts single maximum executable time, and according to single industry The time and total execution duration management business logic of script that actual execution duration, the service logic single of business logic can perform Execution number.The execution time in this step is all accurate to millisecond.When PHP scripts start to perform, it is necessary to when recording Between, to calculate remaining time.
Specifically, this step is realized by performing time control module, as shown in figure 3, the module is mainly including following Step:
Step1:Calculate the time that service logic single can perform, as t/n;
Step2:Start timing;
Step3:Perform the service logic call back function in configuration;
Step4:The execution duration t1 of service logic is calculated, the time for starting timing in Step2 is subtracted with current time;
Step5:Calculate the execution duration t2 of PHP scripts, with current time subtract PHP scripts start perform time (When PHP scripts start to perform, the time of record);
Step6:Calculate whether the remaining execution duration (t-t2) of script performs 1.5 service logics enough, that is, judge Whether t-t2 is more than or equal to 1.5*t1;If greater than or equal to then perform Step7, Step9 is otherwise performed.It is in fact, remaining Perform duration to should be greater than or can perform service logic next time equal to the execution time of 1 service logic, but consider industry The time that logic of being engaged in performs is unstable.The execution of a preceding service logic can be exceeded by being possible to the time that service logic performs next time Time, especially when the time that last time service logic performs is longer then next script can wait, waste money Source, therefore, in order to ensure that more sufficient service logic performs the time, be especially to try to avoid script terminate after script next time Waited, we take 1.5 times of service logic times as criterion, it can be ensured that the maximum execution time of service logic is not In the case of more than 1.5 times of minimum execution time, the startup of script next time is not influenceed.
Step7:Judge whether the time t1 of the actual execution of service logic once is less than what service logic single can perform Time (t/n);When less than when perform Step8;Otherwise Step2 is performed;
Step8:Pause t/n-t1 the times;Then Step2 is performed;Due to the pause t/n-t1 times, therefore we control often The execution time of secondary service logic is not less than t/n, this can maximum number that performs of limit service logic be no more than n, while always The execution time is no more than t.
Step9:Terminate.
By step C, the invention provides more accurately managing to perform time function, by single execution duration and always The control of duration, it is ensured that perform multiple service logic and perform duration no more than the maximum of script.The time is performed in service logic not In the case of more than 0.5 second, we can be such that the service logic number per minute that performs reaches 120 times, be fully able to realize second level Response.
After execution of step C, it is also necessary to delete lock file.
Method and system provided by the invention is not limited to PHP language, be also applicable in such as JavaScript other In script.
Technological means disclosed in the present invention program is not limited only to the technological means disclosed in above-mentioned embodiment, in addition to Formed technical scheme is combined by above technical characteristic.It should be pointed out that for those skilled in the art For, under the premise without departing from the principles of the invention, some improvements and modifications can also be made, these improvements and modifications are also considered as Protection scope of the present invention.

Claims (5)

1. the sustainable operation method of script, it is characterised in that comprise the following steps:
Step A, script is periodically started using timing starter;
Step B, prevent complications from producing by locking file:
Step B-1, check that lock file whether there is, when in the absence of lock file, create lock file and perform step C;Work as presence When locking file, step B-2 is performed;
Step B-2, periodically reexamine lock file and whether there is, if allowing original existing lock file quilt in the time waiting Deletion then creates new lock file, and performs step C;If original existing lock file in the time is allowed still to exist waiting Then perform step B-3;
Step B-3, lock file is checked from being created to whether the current time exceeds schedule time, if it exceeds the stipulated time, then Delete original existing lock file and create new lock file;If being no more than the stipulated time, terminate script operation;
Step C, circulation performs service logic within the whole PHP scripts single maximum executable time, and is patrolled according to single business Total execution duration management business logic of actual execution duration, the time that service logic single can perform and the script collected is held Places number, is specifically included:
Step1:Calculate the time t/n that service logic single can perform, the time that the service logic single can perform=whole The readjustment frequency n of service logic in maximum executable time t/PHP one life cycle of script of individual PHP scripts single;
Step2:Start timing;
Step3:Perform the service logic call back function in configuration;
Step4:The execution duration t1 of service logic is calculated, the time for starting timing in Step2 is subtracted with current time;
Step5:Calculate the execution duration t2 of PHP scripts, with current time subtract PHP scripts start perform time;
Step6:Calculate whether the remaining execution duration (t-t2) of script performs 1.5 service logics enough;If greater than or be equal to Step7 is then performed, otherwise performs Step9;
Step7:Judge whether the time t1 of the actual execution of service logic once is less than the time that service logic single can perform (t/n);When less than when perform Step8;Otherwise Step2 is performed;
Step8:Pause t/n-t1 the times;Then Step2 is performed;
Step9:Terminate;
Step D, delete lock file.
2. the sustainable operation method of script according to claim 1, it is characterised in that the step C includes following step Suddenly:
Step C-1, perform service logic call back function;
Step C-2, the execution duration of service logic is calculated,
Step C-3, the remaining execution duration of script is calculated, step is performed when residue is performed when duration performs service logic next time enough Rapid C-4, otherwise terminate to perform;
Step C-4, when being less than the time that service logic single can perform, perform the time of the actual execution of service logic once Step C-5, otherwise perform step C-1;
Step C-5, pause a period of time, until this execution duration performs after being equal to the time that service logic single can perform C-1。
3. the sustainable operation method of script according to claim 1 or 2, it is characterised in that:The t and n are pre-configured with And loaded after step A perform scripts.
4. the sustainable operation method of script according to claim 1, it is characterised in that:Total execution duration of the script It is equal with the start by set date cycle of script.
5. script sustainable operation system, it is characterised in that:Including timing starter, configuration module, con current control module, execution Time control module;
The timing starter can periodically start script;
The configuration module is used to configure in maximum one life cycle of executable time and PHP scripts of whole PHP scripts single The readjustment number of service logic;
The con current control module prevents complications from producing by locking file;
The execution time control module is used for the circulation execution business within the whole PHP scripts single maximum executable time and patrolled Volume, and the time that can be performed according to actual execution duration, the service logic single of single service logic and total execution of script The execution number of duration management business logic, is specifically included:
Step1:Calculate the time t/n that service logic single can perform, the time that the service logic single can perform=whole The readjustment frequency n of service logic in maximum executable time t/PHP one life cycle of script of individual PHP scripts single;
Step2:Start timing;
Step3:Perform the service logic call back function in configuration;
Step4:The execution duration t1 of service logic is calculated, the time for starting timing in Step2 is subtracted with current time;
Step5:Calculate the execution duration t2 of PHP scripts, with current time subtract PHP scripts start perform time;
Step6:Calculate whether the remaining execution duration (t-t2) of script performs 1.5 service logics enough;If greater than or be equal to Step7 is then performed, otherwise performs Step9;
Step7:Judge whether the time t1 of the actual execution of service logic once is less than the time that service logic single can perform (t/n);When less than when perform Step8;Otherwise Step2 is performed;
Step8:Pause t/n-t1 the times;Then Step2 is performed;
Step9:Terminate.
CN201510160037.5A 2015-04-07 2015-04-07 The sustainable operation method and system of script Active CN104731655B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510160037.5A CN104731655B (en) 2015-04-07 2015-04-07 The sustainable operation method and system of script

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510160037.5A CN104731655B (en) 2015-04-07 2015-04-07 The sustainable operation method and system of script

Publications (2)

Publication Number Publication Date
CN104731655A CN104731655A (en) 2015-06-24
CN104731655B true CN104731655B (en) 2018-03-20

Family

ID=53455570

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510160037.5A Active CN104731655B (en) 2015-04-07 2015-04-07 The sustainable operation method and system of script

Country Status (1)

Country Link
CN (1) CN104731655B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105979018A (en) * 2016-07-29 2016-09-28 上海爱数信息技术股份有限公司 State maintaining method and system for file lock
CN110716903A (en) * 2019-09-29 2020-01-21 中信百信银行股份有限公司 Log file cleaning method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101082870A (en) * 2007-07-20 2007-12-05 中兴通讯股份有限公司 Method for restricting parallel execution of shell script
CN102385527A (en) * 2010-09-01 2012-03-21 中兴通讯股份有限公司 Device and method for improving execution efficiency of service scripts
CN103970660A (en) * 2014-05-19 2014-08-06 浪潮电子信息产业股份有限公司 Total system stability automatic test method based on crontab
CN103984612A (en) * 2014-05-28 2014-08-13 浪潮电子信息产业股份有限公司 Unattended pressure testing method based on HPL tool

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
AU2002220999A1 (en) * 2000-11-22 2002-06-03 Zend Technologies Ltd. Method and apparatus for dynamic shared-memory caching of scripting engine product

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101082870A (en) * 2007-07-20 2007-12-05 中兴通讯股份有限公司 Method for restricting parallel execution of shell script
CN102385527A (en) * 2010-09-01 2012-03-21 中兴通讯股份有限公司 Device and method for improving execution efficiency of service scripts
CN103970660A (en) * 2014-05-19 2014-08-06 浪潮电子信息产业股份有限公司 Total system stability automatic test method based on crontab
CN103984612A (en) * 2014-05-28 2014-08-13 浪潮电子信息产业股份有限公司 Unattended pressure testing method based on HPL tool

Also Published As

Publication number Publication date
CN104731655A (en) 2015-06-24

Similar Documents

Publication Publication Date Title
JP4467623B2 (en) Update management program, management node, update management method, and cluster system
US9141374B2 (en) Image forming device, information processing method, information processing program, and recording medium
CN101950253B (en) Method for upgrading optical module firmware in optical network unit by utilizing WEB webpage interface
US20130007739A1 (en) Virtual machine disk image installation
CN109491682B (en) Method for automatically upgrading permission-controllable block chain system based on intelligent contract
CN107844343A (en) The upgrade-system and method of a kind of complex services end application system
SG189385A1 (en) High availability of machines during patching
US8423996B2 (en) Delivery system, server device, terminal device, and delivery method
CN104731655B (en) The sustainable operation method and system of script
CN109766112A (en) A kind of method and device of program white list knowledge base update
CN106095593B (en) A kind of forward and backward scape application behavior synchronous method and device
CN106980493A (en) Firmware management method and apparatus
CN101877655A (en) Network management system, network management server and method
US20070064892A1 (en) Image forming device, information processing method, information processing program, and recording medium
US8495565B2 (en) Service providing apparatus, service providing system, service providing method, and storage medium
CN106708547A (en) Service plug-in management method and system
US20130179708A1 (en) Processing device
JP2016148947A (en) Information processing apparatus, management device, control method of information processing apparatus, control method of management device, and program
CN113687927A (en) Method, device, equipment and storage medium for scheduling and configuring flash tasks
CN101887375B (en) Method and system for implementing man-machine command system
CN104090802A (en) Protection method for network camera power failure
US9699345B2 (en) Processing apparatus, method for controlling the same, and storage medium
CN114153525A (en) AI model service sharing method and system for power grid regulation and control business
CN107018032A (en) A kind of monitoring system server and method
JP6874590B2 (en) Information processing system, management device, control method of information processing system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant