CN104731655A - Script sustainable operation method and system - Google Patents

Script sustainable operation method and system Download PDF

Info

Publication number
CN104731655A
CN104731655A CN201510160037.5A CN201510160037A CN104731655A CN 104731655 A CN104731655 A CN 104731655A CN 201510160037 A CN201510160037 A CN 201510160037A CN 104731655 A CN104731655 A CN 104731655A
Authority
CN
China
Prior art keywords
script
time
service logic
perform
lock file
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.)
Granted
Application number
CN201510160037.5A
Other languages
Chinese (zh)
Other versions
CN104731655B (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 script sustainable operation method and an operation system capable of achieving the script sustainable operation method. The script sustainable operation method comprises the steps of starting a script in a timing mode; loading configuration; checking concurrency conditions; executing service logic within permissive time in a looping mode. The script sustainable operation system comprises a timing starter, a configuration module, a concurrency control module and an execution time control module. The concurrency of the script is avoided, the execution time is short, the second level response can be achieved, and the maintenance cost is reduced. According to the script sustainable operation method and system, the periodic repetitive operation of the script can be achieved, the script can be restarted and ended automatically at regular intervals, therefore, the dynamic deployment of codes can be achieved, manual intervention is not needed, and the maintenance cost is reduced; the execution time of the script can be managed precisely, the time precision is high, and response can reach the level under the second level.

Description

The sustainable operation method and system of script
Technical field
The invention belongs to software technology field, be specifically related to a kind of method and system that can make page script continuous service.
Background technology
Script be traditional write to shorten-compile-link-operational process and the computer programming language created, be applied to the at all levels of computer system, especially obtain extensive utilization in webpage development field.At present, network application is more and more abundanter, and the use of webpage and visual effect be unable to do without script embedded in webpage.Conventional script has JavaScript, ASP, PHP, python, perl, ruby etc.
For PHP language, in web site architecture, after PHP usually can be used to write one section of shell script, make its timing at running background, be commonly called as timing script, timed task.Timed task is commonly used to perform regular task, clears up daily record such as zero point morning every day, sends the report of proxima luce (prox. luc) every morning 8.Have a class timed task to be wish to run without interruption continuously, such as short message sending status upgrades, electronic fax sends state updating, pay status upgrades.For pay status, guest initiates after payment task enters Third-party payment platform, just to need unlatching timed task to check pay status, thus more new state within the payment successful shortest time as far as possible.But it is long that existing timing script execution exists the script single execution time, level response second cannot be reached, need the problems such as manual intervention, maintenance cost height.
Summary of the invention
For solving the problem, the invention discloses a kind of sustainable operation method of script and can realize the operational system of the method, avoid script concurrent, the execution time is short, can reach level response second, reduce maintenance cost.
In order to achieve the above object, the invention provides following technical scheme:
The sustainable operation method of script, comprises the steps:
Steps A, adopts timing starter periodically booting script;
Step B, prevents complications from producing by lock file:
Step B-1, checks whether lock file exists, when there is not lock file, creating lock file and performing step C; When there is lock file, perform step B-2;
Whether step B-2, regularly reexamine lock file and exist, if waiting for that the lock file of original existence in the permission time is deleted, creating new lock file, and performing step C; If waiting for that the lock file of original existence in the permission time still exists, perform step B-3;
Step B-3, checks whether lock file exceeds schedule time from being created to the current time, if exceeded schedule time, then deletes the lock file of original existence and creates new lock file; If be no more than the stipulated time, then terminate script and run;
Step C, can perform service logic by execution time Inner eycle whole PHP script single is maximum, and the execution number of times of total execution duration management service logic according to the actual execution duration of single service logic, time that service logic single can perform and script;
Step D, deletes lock file.
Further, described step C comprises the steps:
Step C-1, performs service logic call back function;
Step C-2, calculates the execution duration of service logic,
Step C-3, calculate script residue perform duration, when remain perform duration enough perform next time service logic time perform step C-4, otherwise terminate perform;
Step C-4, when service logic is actual perform time be once less than the time that service logic single can perform time, perform step C-5, otherwise perform step C-1;
Step C-5, pauses a period of time, until this performs after duration equals the time that service logic single can perform perform C-1.
Further, described service logic single can perform time=whole PHP script single is maximum can the readjustment frequency n of service logic in execution time t/PHP script life cycle, described t and n is pre-configured and load after steps A performs script.
Further, total execution duration of described script is equal with the start by set date cycle of script.
Present invention also offers the operational system that can realize above-mentioned script sustainable operation method, comprise timing starter, configuration module, con current control module, execution time control module; Wherein timing starter can periodically booting script, and configuration module can the readjustment number of times of service logic in execution time and PHP script life cycle for configuring that whole PHP script single is maximum; Con current control module prevents complications from producing by checking, creating or delete lock file; Execution time control module is used for perform service logic by execution time Inner eycle whole PHP script single is maximum, and the execution number of times of total execution duration management service logic according to the actual execution duration of single service logic, time that service logic single can perform and script.
Compared with prior art, tool of the present invention has the following advantages and beneficial effect:
1. the periodicity that can realize script reruns, and script can regularly autoboot and end, thus can the Dynamical Deployment of code, without the need to manual intervention, reduces maintenance cost.
2. the execution time of pair script accurately manages, and time precision is high, can reach below level second.
3. eliminate PHP script concurrent, avoid that the concurrent resource brought is fought for, result Unpredictability.
4. reduce system complexity, avoid the problem such as RAM leakage, resource deadlock that the long-time running of PHP code brings, played the strong point of PHP language.
Accompanying drawing explanation
Fig. 1 is the sustainable operation method step process flow diagram of script provided by the invention;
Fig. 2 is step B control flow chart;
Fig. 3 is step C control flow chart.
Embodiment
Below with reference to specific embodiment, technical scheme provided by the invention is described in detail, following embodiment should be understood and be only not used in for illustration of the present invention and limit the scope of the invention.
The invention provides a kind of sustainable operation method of script and corresponding system, the circulation continuous that can realize script runs, and overcomes many disadvantages of the prior art, below for PHP script, will be described in detail.Operational system mainly comprises following four modules: timing starter, configuration module, con current control module, execution time control module, timing starter is used for start by set date script, configuration module is for configuring correlation parameter, con current control module is used for creating and delete lock file, and by preventing same script concurrence performance to the inspection of lock file, execution time control module performs service logic and the execution frequency of management service logic for circulating.Method flow provided by the invention as shown in Figure 1, comprises the steps:
Steps A, adopts timing starter periodically booting script.We can use the timer of operating system, as the crontab of linux, can periodically start PHP script like this, such as: we arrange the initiation culture of PHP script in crontab, and startup per minute 1 time.Timing rpms restart script RPMS makes PHP code no longer need long-time execution, when we arrange per minute restart one time time, as long as the execution time of a PHP script reaches one minute, do not need running down year in year out.In addition, due to script autoboot per minute once, and the code of PHP can upgrade at any time, after fresh code is issued, do not need manually to restart PHP process, to when starting PHP script next time, newly deployed code will be performed, reach the effect of " in script implementation upgrade software, and system need not be restarted ".
When performing script, also need to carry out con current control and time controling, this just needs first to configure two crucial parameters---whole PHP script single maximum can execution time t(give tacit consent to 1 minute), the readjustment frequency n (being usually no more than 60 times) of service logic and the call back function of service logic in PHP script life cycle.Meanwhile, the call back function execution time of application claims service logic is less than t/n.These parameters above-mentioned and call back function are all configured in configuration module, after booting script, be namely loaded into configuration.
Step B, execution concurrence control module, prevents complications from producing by checking, creating or delete lock file.As shown in Figure 2, key step is this step control flow:
Generate the title of lock file, check whether lock file exists, when there is not lock file, creating lock file and performing subsequent step; Whether when there is lock file, also regularly will reexamine lock file and exist, if within the wait permission time, the lock file of original existence is deleted, creates new lock file, and performs subsequent step; If within the wait permission time, the lock file of original existence still exists, check whether lock file exceeds schedule time from being created to the current time, if exceeded schedule time, then deletes the lock file of original existence and creates new lock file; If be no more than the stipulated time, then terminate script and run.
The wait permission time is set to t/3 by this example, and the time of regularly reexamining lock file is decided to be inspection per second once, and the stipulated time is set to 3t, is attached to the variety of problems that may exist when script performs, enumerates several situations that may exist in stepb:
Normal scene: after script startup, is checked through and there is not lock file, at this moment creates lock file, and performs subsequent logic (step C), executes rear deletion lock file, terminates script and perform.
Wait for scene: after script startup, be checked through and there is lock file, reexamine p.s. once; At t/3, (1/3rd t) in the time, and the script that old lock file is created lock file is deleted, and now creates new lock file, and performs subsequent logic, executes rear deletions lock file, terminate script execution.This situation is that last creates last consuming time far away super second from the bottom time of performing service logic in the script of lock and performs and consuming timely just to there will be.We wish that last script terminates to perform so a script terminates in wait as early as possible; If but a upper script do not terminate for a long time so this start after wait beyond doubt at consumption server resource, consider when server accidental abnormal, major part service logic can end process in t/3, therefore we get a suitable wait and allow time value t/3, can not consume too much server resource.
Etc. scene to be interrupted: after script startup, be checked through and there is lock file, reexamine p.s. once; When just more than the t/3 time, old lock file still exists, and be checked through lock file be no more than 3t (t of three times) now from being created to, terminate script perform.
Scene four: wait for and continue scene, after script startup, is checked through and there is lock file, reexamine p.s. once; To during just more than the t/3 time, old lock file still exists, and is checked through lock file from being created to now more than 3t (t of three times), delete old lock file, create new lock file, perform subsequent logic (execution time control module), delete lock file, terminate.When last service logic cannot continue to perform because of resource link time-out (as overtime in DataBase combining, socket is overtime etc.), no longer wait for previous script as long as exceed our the of long duration of setting but start to perform the service logic in current script after deletion lock file.
Should illustrate, above-mentioned wait allows time and stipulated time to adjust as required, and reaches following effect as far as possible: when slight abnormality appears in server, and the waste that minimizing etc. are to be generated as far as possible, increases the execution number of times of service logic as far as possible; When there is great exception and recover in server, can recover voluntarily script run and without the need to manual intervention.
Lock file in con current control module, lock file filename, uniqueness is realized by carrying out md5 to the complete trails of script file, under lock file leaves the catalogue of specifying in, such as, under linux /tmp/php/script/lock/ catalogue, the content of lock file is the timestamp that precision arrives millisecond, deposits the time of lock file generated.Under ideal case, lock file creates when script startup, deletes 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 script performs, and this ensures that theres when PHP script self has occurred that code is abnormal and also can delete lock file, do not affect and run next time.
Step C, can perform service logic by execution time Inner eycle whole PHP script single is maximum, and the execution number of times of total execution duration management service logic according to the actual execution duration of single service logic, time that service logic single can perform and script.Execution time in this step is all accurate to millisecond.When PHP script starts to perform, just need to record the time, to calculate excess time.
Specifically, this step is realized by execution time control module, and as shown in Figure 3, this module mainly comprises the following steps:
Step1: the time that computing service logic single can perform, is t/n;
Step2: start timing;
Step3: perform the service logic call back function in configuration;
Step4: the execution duration t1 calculating service logic, deducts in Step2 the time starting timing by current time;
Step5: the execution duration t2 calculating PHP script, deduct by current time the time (when PHP script starts to perform, the time of record) that PHP script starts execution;
Step6: calculate script residue and perform duration (t-t2) whether enough execution 1.5 service logics, namely judge whether t-t2 is more than or equal to 1.5*t1; If be more than or equal to, perform Step7, otherwise perform Step9.In fact, namely the execution time that residue execution duration should be more than or equal to 1 service logic can perform service logic next time, but considers that the time that service logic performs is unstable.The time that likely service logic performs next time can exceed the time that a front service logic performs, especially next script then can be made to wait for when the time that last service logic performs is longer, waste resource, therefore, in order to ensure the comparatively sufficient service logic execution time, especially after avoiding script to terminate, script is waited for next time as far as possible, we get 1.5 times of service logic times as criterion, when can guarantee that the maximum execution time of service logic is no more than 1.5 times of minimum execution time, do not affect the startup of script next time.
Step7: judge whether the actual time t1 once of performing of service logic is less than the time (t/n) that service logic single can perform; Step8 is performed when being less than; Otherwise perform Step2;
Step8: pause t/n – t1 time; Then Step2 is performed; Due to the pause t/n – t1 time, the execution time that therefore we control each service logic is not less than t/n, and this maximum execution number of times of limit service logic can be no more than n, and total execution time is no more than t simultaneously.
Step9: terminate.
By step C, the invention provides and manage execution time function more accurately, by performing the control of duration and total duration to single, guarantee to perform repeatedly the maximum execution duration that service logic is no more than script.When the service logic execution time is no more than 0.5 second, we can make service logic execution number of times per minute reach 120 times, can realize level response second completely.
After execution of step C, also need to delete lock file.
Method and system provided by the invention is not limited to PHP language, also can be applicable to as in other scripts such as JavaScript.
Technological means disclosed in the present invention program is not limited only to the technological means disclosed in above-mentioned embodiment, also comprises the technical scheme be made up of above technical characteristic combination in any.It should be pointed out that for those skilled in the art, under the premise without departing from the principles of the invention, can also make some improvements and modifications, these improvements and modifications are also considered as protection scope of the present invention.

Claims (5)

1. the sustainable operation method of script, is characterized in that, comprise the steps:
Steps A, adopts timing starter periodically booting script;
Step B, prevents complications from producing by lock file:
Step B-1, checks whether lock file exists, when there is not lock file, creating lock file and performing step C; When there is lock file, perform step B-2;
Whether step B-2, regularly reexamine lock file and exist, if waiting for that the lock file of original existence in the permission time is deleted, creating new lock file, and performing step C; If waiting for that the lock file of original existence in the permission time still exists, perform step B-3;
Step B-3, checks whether lock file exceeds schedule time from being created to the current time, if exceeded schedule time, then deletes the lock file of original existence and creates new lock file; If be no more than the stipulated time, then terminate script and run;
Step C, can perform service logic by execution time Inner eycle whole PHP script single is maximum, and the execution number of times of total execution duration management service logic according to the actual execution duration of single service logic, time that service logic single can perform and script;
Step D, deletes lock file.
2. the sustainable operation method of script according to claim 1, is characterized in that, described step C comprises the steps:
Step C-1, performs service logic call back function;
Step C-2, calculates the execution duration of service logic,
Step C-3, calculate script residue perform duration, when remain perform duration enough perform next time service logic time perform step C-4, otherwise terminate perform;
Step C-4, when service logic is actual perform time be once less than the time that service logic single can perform time, perform step C-5, otherwise perform step C-1;
Step C-5, pauses a period of time, until this performs after duration equals the time that service logic single can perform perform C-1.
3. the sustainable operation method of script according to claim 1 and 2, it is characterized in that: described service logic single can perform time=whole PHP script single is maximum can the readjustment frequency n of service logic in execution time t/PHP script life cycle, described t and n is pre-configured and load after steps A performs script.
4. the sustainable operation method of script according to claim 1, is characterized in that: total execution duration of described script is equal with the start by set date cycle of script.
5. script sustainable operation system, is characterized in that: comprise timing starter, configuration module, con current control module, execution time control module; Described timing starter can periodically booting script; Described configuration module can the readjustment number of times of service logic in execution time and PHP script life cycle for configuring that whole PHP script single is maximum; Described con current control module prevents complications from producing by lock file; Described execution time control module is used for perform service logic by execution time Inner eycle whole PHP script single is maximum, and the execution number of times of total execution duration management service logic according to the actual execution duration of single service logic, time that service logic single can perform and script.
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 true CN104731655A (en) 2015-06-24
CN104731655B 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)

Cited By (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 (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020062354A1 (en) * 2000-11-22 2002-05-23 Suraski Ze?Apos;Ev Method and apparatus for dynamic shared-memory caching of scripting engine product
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

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020062354A1 (en) * 2000-11-22 2002-05-23 Suraski Ze?Apos;Ev Method and apparatus for dynamic shared-memory caching of scripting engine product
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

Cited By (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

Also Published As

Publication number Publication date
CN104731655B (en) 2018-03-20

Similar Documents

Publication Publication Date Title
US10248671B2 (en) Dynamic migration script management
CN109831500B (en) Synchronization method for configuration file and Pod in Kubernetes cluster
US10585659B2 (en) Enabling tenant administrators to initiate request driven peak-hour builds to override off-peak patching schedules
CN101950253B (en) Method for upgrading optical module firmware in optical network unit by utilizing WEB webpage interface
US10678533B2 (en) Enhanced server farm patching system for enabling developers to override off-peak patching schedules
US20150324232A1 (en) Resource management method and apparatus for virtual machine system, and virtual machine system
CN109491682B (en) Method for automatically upgrading permission-controllable block chain system based on intelligent contract
CN102681917B (en) A kind of operating system and restorative procedure thereof
CN103064717B (en) A kind of apparatus and method of parallel installation of software for cluster system
JP2009230171A (en) Update management program, management node, update management method, and cluster system
CN105388990A (en) Power saving processing method and apparatus for terminal device
CN102664950B (en) Data communication method between welding power sources and computers
US7925761B2 (en) System and method for implementing a dead man dependency technique for cluster resources
CN103297275A (en) Dynamic discovery and loading system and method for Web network management client module
CN113626280B (en) Cluster state control method and device, electronic equipment and readable storage medium
CN104731655A (en) Script sustainable operation method and system
CN111371599A (en) Cluster disaster recovery management system based on ETCD
CN106095593B (en) A kind of forward and backward scape application behavior synchronous method and device
CN103442292A (en) Method for processing smart television software errors
CN103903312A (en) Method and device for executing automatic inspection
CN101877655A (en) Network management system, network management server and method
CN113687927A (en) Method, device, equipment and storage medium for scheduling and configuring flash tasks
CN104090802A (en) Protection method for network camera power failure
CN111917588A (en) Edge device management method, device, edge gateway device and storage medium
CN114553917B (en) Block chain-based network intelligent treatment method

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