Disclosure of Invention
The technical problem to be solved by the present invention is to provide an engine system based on a scripting language, aiming at the above-mentioned defects in the prior art, to solve the problems that high concurrency cannot be performed and repeated order issuing processing is easy to occur, a logic layer and a presentation layer cannot be effectively separated, a software coupling degree is high, and a software development efficiency is low.
To solve the technical problem, the present invention provides an engine system based on a scripting language, the engine system comprising a database access module, an HTTP service module, a producer-consumer module, and a timing execution module, wherein,
the database access module is used for calling a configuration file by using a scripting language and building a database access model, and the database access model can be interacted with a database and can be called by an HTTP service module, a producer consumer module and a timing execution module;
the HTTP service module calls a configuration file by using a script language, builds an HTTP server and dynamically adjusts the processing capacity of the HTTP server;
the producer consumer module calls a configuration file by using a script language, builds a producer model, a consumer model and a buffer area, the producer model produces data and carries out judgment and repeat processing, the data are placed in the buffer area, and the consumer model reads the data from the buffer area;
and the timing execution module calls the configuration file by using a script language and builds a timing execution model for executing the task at a fixed time.
Wherein, the preferred scheme is: the engine system is preset with configuration files of a database access module, an HTTP service module, a producer consumer module and a timing execution module, and is also preset with a base class for providing a method for calling the configuration files.
Wherein, the preferred scheme is: the engine system is preset with a database access module, an HTTP service module, a producer consumer module and a script language of a timing execution module, and is also preset with a base class for providing a method for executing the script language.
Wherein, the preferred scheme is: the script language is Lua script language.
Wherein, the preferred scheme is: the database access module is provided with a database connection pool management class, a database connection pool class and a database access method class, wherein the database connection pool management class is used for providing a method for starting the database connection pool, the database connection pool class is used for calling a configuration file and building a database connection pool, and the database access method class is used for providing an access method of the database and can use a script language to access the database through the access method.
Wherein, the preferred scheme is: the database is a MYSQL database.
Wherein, the preferred scheme is: the HTTP server comprises an HTTP client and an HTTP server, the HTTP service module is provided with a plurality of objects responding to the HTTP client and a plurality of objects responding to the HTTP server, and the HTTP service module is further provided with a plurality of objects loading script languages.
Wherein, the preferred scheme is: the number of the producer models is one, and the number of the consumer models is multiple.
Wherein, the preferred scheme is: the engine system also comprises a port module, wherein the port module creates a plurality of working threads, constructs an IOCP model under Windows and constructs an EPLL model under Linux.
Wherein, the preferred scheme is: the engine system further comprises an HTTP client module, the HTTP client module calls the configuration file by using a script language and builds an HTTP client, the engine system further comprises a response module, the response module provides a method for sending a request response to the HTTP client and a method for sending request data to the HTTP server, and the response module further provides a base class for creating the method.
Compared with the prior art, the invention has the beneficial effects that the invention can rapidly complete the initialization of each large module by designing the engine system based on the script language, wherein the engine system is stored with the configuration files of each large module and the script language related to each large module, and the script language is used for calling the configuration files; the engine system is also provided with base classes corresponding to the large modules, so that the scheduling of the large modules is facilitated, and the coupling degree of software can be effectively reduced; in addition, the producer consumer module has concurrency capability and repeated processing capability, development efficiency can be improved, repeated order issuing processing does not exist, and error rate is reduced.
Detailed Description
The preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
As shown in fig. 1 to 10, the present invention provides a preferred embodiment of a scripting language-based engine system.
Specifically, referring to fig. 1, a scripting language-based engine system is characterized in that: the engine system comprises a database access module 100, an HTTP service module 200, a producer consumer module 300 and a timing execution module 400, wherein the HTTP service module 200, the producer consumer module 300 and the timing execution module 400 can respectively call the database access module 100 at will.
Referring to fig. 2, the database access module 100 using a scripting language to call a configuration file, and building a database access model, the database access model being interactive with a database and being called by the HTTP service module 200, the producer consumer module 300, and the timing execution module 400; and the number of connections can be modified through configuration files according to business requirements.
In this embodiment, the database access module 100 is provided with a database connection pool management class, a database connection pool class, and a database access method class, where the database connection pool management class is used to provide a method for starting a database connection pool, the database connection pool class is used to retrieve a configuration file and build a database connection pool, and the database access method class is used to provide an access method for a database, and a scripting language may be used to access the database through the access method. That is, referring to fig. 2, the cmssqlconnectpoolmanager class is a connection pool management class that accesses a MYSQL-type database, and the initialization, start, addition, and the like of each database connection pool provide a method by this class. Thus, database connection pool access only requires that such be exposed; the CMySqlConnectPool class is a database connection pool class, the database connection pool is a channel for accessing the database by a database access model, the class is a thread class which is inherited to the ACE _ Task _ Base class, and the rule management of the database connection pool is completed by reading information in a configuration file; CMySqlDB classes provide methods for access to a MYSQL type database, such as connecting the database, executing SQL, taking a result set and the like, which are exposed to lua scripting language through luabind modes, so that the methods can be directly used for accessing the database when scripts are written, and meanwhile, the methods are also needed when a database connection pool is established in the CMySqlConnectPool classes. By the database connection pool access mode, the problem that a large amount of system resources are consumed when the database is accessed in a connected mode can be solved. Preferably, the database is a MYSQL database.
Referring to fig. 3, the HTTP service module 200 calls a configuration file using a scripting language, builds an HTTP server, and dynamically adjusts the processing capability of the HTTP server, for example, by modifying the configuration file, the maximum number of connection requests to be maintained and the connection processing capability can be modified.
In this embodiment, the HTTP service module 200 needs to consider both the received data of the network link, the connection error or the timeout processing, and also the script execution corresponding to each link, which is much more complicated than other functional modes. The HTTP server includes an HTTP client and an HTTP server, the HTTP service module 200 creates a plurality of objects responding to the HTTP client and a plurality of objects responding to the HTTP server, and the HTTP service module 200 also creates a plurality of objects loading a script language. That is, referring to fig. 3, in this section, the chttpserververprocessor class is a core class of the server, and an object m _ ClientHandleArray of the ChttpClientHandle class and an object m _ LuaClientProcessorArray of the cluahttpclientprocessorprocessorare defined therein; in this way, the connection processing of the socket server and the loading and execution work of the corresponding connection script are completed by scheduling the two objects; for receiving the connected Socket connection, an independent thread is adopted to specially use the connection request of the accept client. Therefore, a CSockestacceptThread class is introduced here, and the inheritance of the class is similar to that of ACE _ Task _ Base; because single accept thread does not process the connection when more connections are accessed, a plurality of objects m _ accept thread are created, and therefore, the aim that a plurality of clients are connected with a plurality of servers is facilitated.
The producer consumer module 300 calls a configuration file by using a script language, builds a producer model, a consumer model and a buffer area, the producer model produces data and performs judging and reprocessing, the data is placed in the buffer area, the consumer model reads the data from the buffer area, the producer model controls the data production rate, the consumer model processes the actual logic flow of the data, and meanwhile, the producer model and the consumer model have concurrency capability and simultaneously perform corresponding tasks. Referring to fig. 4, the CProducerConsumer module class is a class exposed by the producer consumer execution module, the m _ ProducerConsumer is an object of the CProducerConsumer class, and the m _ ModuleInfo is an object of the CProducerConsumer ModuleInfo class, which are all member objects of the CProducerConsumer class, and since the producer model is one and the consumer model is multiple, there is only one object m _ producer of the CLuaConsumer class in the CProducerConsumer class, and the objects of the clua producer classes define the m _ ConsumerArray in an array manner here; thus, the execution of such scripts and the reading of configuration information can be accomplished by scheduling objects of the cproducerconsummermodule class.
The timing execution module 400 calls the configuration file by using a scripting language, and builds a timing execution model, wherein the timing execution model is used for executing the task at a fixed time and can quickly complete the task, namely, the task can meet the requirements, such as data statistics or exception handling. Referring to FIG. 5, the CScheduleExecutionModule class completes the processing of the timing type task and exposes the external class, and m _ Processor is the object of the CScheduleExecutionLuaprocessor class, and m _ ModuleInfo is the object of the CScheduleExecutionModule class, which are all the member objects of the CScheduleExecutionModule class.
In addition, the producer consumer module 300 can perform judging and reprocessing, and can solve the problem that high concurrency and unrepeatable order issuing processing is required at regular time, for example, regular statistics of service data, and analysis of current service quality data is achieved. The analysis of the business data is to establish an effective analysis model, and the algorithm of the model is verified without using the collected data, possible internal inevitable correlation events are analyzed from countless accidental data, and finally, instructive suggestions and reports are given, so that the product design and operators are helped to improve the product, the user experience is enhanced, and the targeted marketing is finished.
More specifically, referring to fig. 6, the engine system is preset with profiles of the database access module 100, the HTTP service module 200, the producer consumer module 300, and the timing execution module 400, and is also preset with a base class for providing a method of calling the profile. That is, referring to fig. 6, the CModuleInfoBase class is a base class of the configuration file, and is used for other classes to inherit, where the base class provides basic methods that all need to be used, such as LoadBaseConfig basic information reading, user initial setting information or configuration information reading setting, and the cschedledexecutormoduleinfo class is a configuration file class of the timing execution module 400 and is only used for operating the configuration file of the timing execution module 400; the chttpservervmoduleinfo class is a configuration file class of the HTTP service module 200, is only used for operating the configuration file of the HTTP service module 200, and does not interfere with the configuration of other modules; the cproducerconsummermmoduleinfo class is a configuration file class of the producer consumer module 300 and is only used for operating the configuration file of the producer consumer module 300, so that each module calls the configuration file operation class corresponding to the module to complete the operation and control of the configuration file, the scheduling of each large module is facilitated, the coupling degree can be effectively reduced, and the development efficiency is improved.
Still specifically, referring to fig. 7, the engine system is preset with scripting languages of the database access module 100, the HTTP service module 200, the producer-consumer module 300, and the timing execution module 400, and is also preset with a base class for providing a method for executing the scripting language, wherein the scripting language is Lua scripting language. That is, referring to fig. 7, the cluathhreadbase class is a base class for executing a script language, providing a common method for executing various types of scripts; meanwhile, the method of AddClassToState et al uses luabind to expose the partial classification method to the lua environment, and the partial classification method inherits the ACE _ Task _ Base class, so the partial classification method belongs to the thread class. The cschedelexecutorluaprocessor class is a subclass of cluathhreadbase, which is used to load scripts that execute the timed execution module 400. It is worth mentioning that in this class the svc function performs the timed execution function. The CLuaConsumer class and the CLuaProducer class are respectively responsible for script loading and execution of the producer consumer module 300, and queues shared by the producer model and the consumer model, generation of 'products' and taking of 'products' are independently completed in various types of svc functions. The CLuaHttpClientProcessor class is a script execution for processing the HTTP service module 200. The CLuaTools class may be referred to as the tools class, and objects of this class may be used in the CLuaThreadBase class, which provides a self-embedded approach to exposing global classes and engines to the LUA environment.
Further, referring to fig. 8, the engine system needs to solve the multi-user concurrent request, and due to different characteristics of the operating systems, the completion IOCP model is adopted under Windows, and the EPOLL model is adopted under Linux, so the engine system further includes a port module, the port module creates a plurality of working threads, constructs the IOCP model under Windows, and constructs the EPOLL model under Linux. That is, referring to fig. 8, the CSocketMessageProcessor class inherits the ACE _ Task _ Base thread class, and under Windows these threads continuously scan through the port queue by calling the GetQueuedCompletionStatus interface, and under Linux, query the network interface through the epoll _ wait interface; the CSocketMessageProcessPool class is used to create multiple worker threads of the CSocketMessageProcessor type.
Further, referring to fig. 9, the engine system further includes an HTTP client module, where the HTTP client module calls a configuration file using a scripting language to build an HTTP client, and the engine system further includes a response module, where the response module provides a method for sending a request response to the HTTP client and a method for sending request data to the HTTP server, and the response module further provides a base class for creating the method. That is, for the convenience of socket processing, we define a socket class, and the link processing for the HTTP client and the HTTP server is processed by the definition of the two classes. The CSockeHandle class is a socket class which is used as a base class and can be used for a client and a server for creating the socket, and the CSockeHandle class provides basic methods for creating, monitoring, connecting, sending and the like of the socket. The CHttpUtil class is a corresponding class of methods provided by the engine tool as the HTTP client, and among them, for example, methods for sending data to the HTTP server are provided. The CHttpClientHandle class is a method class provided when the engine tool is used as an HTTP server, and provides methods such as a method for acquiring a remote ip address and a method for returning a response.
Fig. 10 shows the final execution of the engine system, and the CLogicProcess2App class is the final execution class of the script engine, and thus inherits the ACE _ NT _ Service class, which ensures that the system runs in a Service mode under Windows. The m _ ModuleManager is an object of a CModeManager class, and the loading of each large module is completed by the class, so that the m _ ModuleManager is used as a member variable in a CLOGcProcess 2App class and can complete the scheduling of each large module, the engine system operates according to which mode, the mode depends on the function to be realized, and the mode is correspondingly configured in a configuration file, and the process is simplified. The m _ MysqlConnectPoolManager is an object of the CMySqlConnectPoolManager class, and the object is used as a member object in the CLogicProcess2App, so that the engine system can be ensured to complete the rule configuration of the database thread pool, and the required functions are realized; the m _ socketmessageprocesspool is an object of the csocketmessageprocesspool class and is available in the clogicepcess 2App, which ensures that the engine completes the creation of the network receive thread.
In summary, the above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present invention should be included in the protection scope of the present invention.