Any active ues collection maintenance system and method based on time wheel disc and broadcast state
Technical field
It is specifically a kind of based on time wheel the present invention relates to the maintenance technology field of any active ues collection in net cast
Any active ues collection maintenance system and method for disk and broadcast state.
Background technique
With the rapid development of Internet technology, more and more users can be used the terminals such as computer, mobile phone and pass through net
Network watches Online Video live streaming.Online Video live streaming refers to the live video direct broadcast service carried out using Internet resource,
It is synchronized and is published on network by the video capture at scene, user can see live feelings in real time the same time on network
Condition.
In the business scenario of net cast website, many direct broadcasting room main broadcasters are initiating in initiation interactive event or website
When special activities, need to interact just for any active ues or active user on website watched between current live,
At this moment it just needs that any active ues are recorded and updated in real time by an any active ues collection.
Currently, safeguarding the usual thinking of any active ues collection are as follows: when server continuous a period of time in net cast field
Interior (it is generally necessary to the customized time, which is time-out duration Timeout) does not receive user behavior data, just this
User eliminates any active ues collection.Specifically, it is generally divided into following two mode:
(1) it is directed to each user, saves corresponding " finally receiving the time lastReceiveTime of behavioral data ";So
Afterwards by a timer, each second traverses the user conversation of all users, rejects those users for meeting following formula
Session:
Current time now- finally receives the time lastReceiveTime > time-out duration Timeout of behavioral data.
It is overtime every time but since this way overall situation is provided only with a repetition timer repeated timer
It will check whole user session informations, it is this if user conversation number is bigger (as kept a users up to ten thousand simultaneously)
The inspection amount of mode will be very big, and entire checking process is time-consuming serious, reduces real-time.
(2) substantially identical as first way, the difference is that a disposable timer is arranged for each user conversation
One-shot timer just disconnects this session when timer expiry, and when receiving user behavior data every time
Update the timer.
Although the method improves the efficiency of inspection to a certain extent, need to be arranged many disposable timers, and
It needs continually to update timer.If linking number is larger, " timer queue to be updated " can be caused stress, when serious
It also will cause system congestion even to collapse.
Summary of the invention
The purpose of the invention is to overcome the shortcomings of above-mentioned background technique, provide a kind of based on time wheel disc and broadcasting shape
Any active ues collection maintenance system and method for state, video render state when can watch video based on normal users generate active
User's collection, while any active ues collection is kept updating using time wheel disc, not only in time efficiently, and system will not be caused
Larger load ensure that effective progress of interactive event.
To achieve the above objectives, the present invention provides a kind of based on any active ues collection of time wheel disc and broadcast state maintenance system
It unites, including several user terminals and a live streaming Platform Server, is provided with broadcast state logging modle in each user terminal,
Caching preprocessing module, distributed computing module and any active ues collection functional module in real time are provided in live streaming Platform Server;
The broadcast state logging modle is used for: the broadcast state information of video flowing when record user watches live streaming in real time;
Give the broadcast state information reporting of record to live streaming Platform Server;
The caching preprocessing module is used for: carrying out caching and pre- place to the broadcast state information that each user terminal reports
Reason;Timing will caching and pretreated all broadcast state information by be sent in the form of several data slices it is distributed in real time in terms of
Calculate module;
The distributed computing module in real time includes several real-time computational submodules, and distributed computing module in real time is used for
The each data slice received is distributed into a specified real-time computational submodule according to Hash strategy;It is each to calculate submodule in real time
Block is parsed and is verified to the broadcast state information in data slice, and the corresponding user of broadcast state information being verified is added
It is added in the corresponding any active ues collection fragment of current time, any active ues collection fragment is by any active ues collection according to specified
Actively several fragments that the calculating period is divided into;
Any active ues integrate functional module and are used for: using the specified active calculating period as the period, by current time pair
Any active ues collection fragment answered is updated into the time wheel disc created, and the time wheel disc is a kind of data structure, main body
It is an end to end circular list, includes the unit that several are referred to as slot in the circular list, filled in each slot
There is an any active ues collection fragment, and the circular list also has the pointer of a direction tail of the queue.
Based on the above technical solution, broadcast state information includes: video stream mode, User ID and according to specific rule
The identification code then generated.
Based on the above technical solution, the video stream mode includes video render, video stream buffer area is full, regards
Frequency streambuf is empty and video playing is closed;The create-rule of the identification code are as follows: timestamp+subscriber terminal equipment API
The terminal device ID+ random number that (Application Programming Interface, Application Programming Interface) obtains.
Based on the above technical solution, any active ues collection functional module is with the specified active calculating period
Period, when the corresponding any active ues collection fragment of current time is updated into the time wheel disc created, specific operation process are as follows:
It is every after the specified active calculating period, any active ues collection fragment in time wheel disc in each slot is to head of the queue Forward one
Lattice;The corresponding any active ues collection fragment of current time is updated in the slot of tail of the queue;By the pointer on time wheel disc to team
Head one lattice of Forward.
The present invention also provides a kind of any active ues collection maintaining method based on time wheel disc and broadcast state, including following step
Rapid: A, the broadcast state logging modle of each user terminal records the broadcast state letter of video flowing when user watches live streaming in real time
Breath;Give the broadcast state information reporting of record to live streaming Platform Server;B, the caching preprocessing module of Platform Server is broadcast live
The broadcast state information that each user terminal reports is cached and pre-processed;C, caching preprocessing module timing will caching and
Pretreated all broadcast state information are sent to distributed real-time computing module in the form of several data slices;It is distributed real
When computing module each data slice distributed into a specified real-time computational submodule according to Hash strategy;D, each meter in real time
Operator module is parsed and is verified to the broadcast state information in data slice, and the broadcast state information being verified is corresponding
User is added in the corresponding any active ues collection fragment of current time;E, any active ues collection functional module is with the active calculating period
For the period, periodically the corresponding any active ues collection fragment of current time is updated into the time wheel disc created.
Based on the above technical solution, it in step B, when the caching preprocessing module is cached, can abandon not
Satisfactory broadcast state information;The undesirable broadcast state information includes: the illegal broadcasting shape of frequency stream mode
State information, User ID are that empty or User ID does not meet the broadcast state information of data field type, timestamp format error
Broadcast state information and type of user terminal identify illegal broadcast state information.
Based on the above technical solution, in step C, the timing of caching preprocessing module will caching and pretreated institute
There is broadcast state information to be sent to distributed real-time computing module in the form of several data slices, specifically include following operation: is slow
It deposits preprocessing module and current cache and pretreated all broadcast state information is sent to distributed meter in real time every 1 second
Module is calculated, broadcast state information is combined into several data slices less than or equal to 1M when sending every time and is sent.
Based on the above technical solution, in step C, distributed computing module in real time is by each data slice according to Hash
Strategy distributes to a specified real-time computational submodule, specifically includes following operation: distributed computing module in real time is each
Data slice distributes a unique ID number, which is pressed to the number modulus of real-time computational submodule, and the remainder of acquisition then corresponds to
The ID number of specified real-time computational submodule;Data slice is distributed to the real-time computational submodule of corresponding ID number.
Based on the above technical solution, step D specifically includes following operation: each computational submodule in real time is to data
Broadcast state information in piece is parsed, and judges that the broadcast state information is according to the identification code of the broadcast state information of parsing
It is no effectively if invalid, directly to abandon the broadcast state information, terminate;If effective, then to the video of the broadcast state information
Stream mode is verified, if verifying does not pass through, directly abandons the broadcast state information, is terminated, if being verified, by the broadcasting shape
The User ID of state information is added in the corresponding any active ues collection fragment of current time.
Based on the above technical solution, step E specifically includes following operation: every by the specified active calculating time
Duan Hou, any active ues collection fragment in time wheel disc in each slot move forward a lattice to head of the queue;By the corresponding active use of current time
Family collection fragment is updated in the slot of tail of the queue;By the pointer on time wheel disc to head of the queue move forward a lattice.
The beneficial effects of the present invention are:
1, video render state when watching video the present invention is based on normal users generates corresponding any active ues collection point
Piece, any active ues collection fragment are several fragments for being divided into any active ues collection according to the specified active calculating period, only
There is the normal user of video render state that any active ues is just used as to be added to any active ues collection corresponding with current time point
In piece;On this basis, while using time wheel disc any active ues collection is kept updating, with the specified active calculating period
For the period, periodically the corresponding any active ues collection fragment of current time is updated into the time wheel disc created, thus completion pair
The timely maintenance of any active ues collection.
Compared with prior art, the present invention is not to use to repeat timer or disposable timer, but be based on video
Stream broadcasting state and time wheel disc are updated maintenance to any active ues collection, not only in time efficiently, and will not make to system
At larger load, can effectively limit the participation of inactive users in certain interactive events, guarantee interactive event it is effective into
Row.
2, in the present invention, any active ues collection fragment is to be divided according to the specified active calculating period, and live
It is also using the specified active calculating period as maintenance period that jump user, which integrates functional module,.This actively calculates the period can be according to reality
Border use needs self-setting and adjustment, and the number of any active ues collection fragment also can be adjusted accordingly, this allows for enlivening use
The statistics granularity at family can be configured and adjust as needed (can liveness, minute liveness or other are active by the hour
Degree calculates to count), and corresponding wheel disc period time can also correspond to adjustment (can be safeguarded by maintenance in 1 hour, 1 minute or its
His safeguards in period), strong flexibility, applicability is high.
3, in the present invention, live streaming Platform Server is provided with caching preprocessing module, which can not only
The broadcast state information that each user terminal reports is cached and pre-processed, moreover it is possible to periodically be owned caching with pretreated
Broadcast state information is sent to distributed real-time computing module in the form of several data slices;Also, the distribution calculates in real time
Module is made of several real-time computational submodules, and each data slice is assigned to the real-time computational submodule of specified one and carries out
Processing, multiple real-time computational submodules can handle multiple data slices simultaneously, and treatment effeciency is high, and real-time is stronger.
It 4, is the real-time computational submodule for selecting to be reported according to Hash strategy, mesh to data slice in the present invention
Be horizontal extension ability in order to improve distributed computing module in real time, allow distributed computing module in real time according to wanting
The scale of the data volume of processing accordingly increases and decreases the number of real-time computational submodule.
Detailed description of the invention
Fig. 1 is the structural frames of any active ues collection maintenance system based on time wheel disc and broadcast state in the embodiment of the present invention
Figure;
Fig. 2 is the structural schematic diagram of time wheel disc;
Fig. 3 is the process of any active ues collection maintaining method based on time wheel disc and broadcast state in the embodiment of the present invention
Figure.
Specific embodiment
With reference to the accompanying drawing and specific embodiment the present invention is described in further detail.
Shown in Figure 1, the embodiment of the present invention provides a kind of based on any active ues collection of time wheel disc and broadcast state dimension
Protecting system, including several user terminals and a live streaming Platform Server are provided with broadcast state record in each user terminal
Module is broadcast live in Platform Server and is provided with caching preprocessing module, distributed computing module and any active ues collection function in real time
Module.
Wherein, broadcast state logging modle is used for: the broadcast state information of video flowing when record user watches live streaming in real time;
Give the broadcast state information reporting of record to live streaming Platform Server.
It is understood that broadcast state information includes: video stream mode, User ID (i.e. the ID of user's uniqueness) and presses
The identification code generated according to ad hoc rules.Video stream mode includes that video render PLAY, video stream buffer area are full
Buffer.Full, video stream buffer area sky Buffer.Empty and video playing close Close;Wherein Buffer.Full
When, user sees video smoothness;When Buffer.Empty, user sees video cardton.The create-rule of the identification code are as follows: timestamp
Terminal device ID (unique ID that terminal device ID is subscriber terminal equipment)+random number that+subscriber terminal equipment API is obtained;It should
Identification code is regular length, and through encryption after generation.
Caching preprocessing module is used for: the broadcast state information that each user terminal reports is cached and pre-processed;It is fixed
When caching and pretreated all broadcast state information are sent in the form of several data slices distributed calculate mould in real time
Block.
Distributed computing module in real time includes several real-time computational submodules, and distributed computing module in real time will be for that will receive
To each data slice distribute to a specified real-time computational submodule according to Hash strategy;Each computational submodule pair in real time
Broadcast state information in data slice is parsed and is verified, and the User ID for the broadcast state information being verified is added to and is worked as
In preceding time corresponding any active ues collection fragment, which refers to: in advance by any active ues collection according to specified
Actively several fragments that the calculating period is divided into.Such as: if the specified active calculating period is 1 hour, any active ues
As soon as collection 24 hours corresponding day, there is 24 corresponding any active ues collection fragments;If the specified active calculating period is 1 minute,
As soon as then any active ues collection is day 24*60=1440 minutes corresponding, there are 1440 corresponding any active ues collection fragments.
Any active ues integrate functional module and are used for: being the period (such as with 1 hour or 1 minute using the specified active calculating period
Deng for the period), the corresponding any active ues collection fragment of current time is updated into the time wheel disc created;As shown in Fig. 2,
The time wheel disc of creation is a kind of data structure, and main body is an end to end circular list (circular buffer),
Include the unit that several are referred to as slot (slot) in the circular list, divides in each slot filled with an any active ues collection
Piece, and the circular list also has the pointer (tail) of a direction tail of the queue.
It is shown in Figure 3, the embodiment of the present invention also provide it is a kind of using above system based on time wheel disc and user's row
For any active ues collection maintaining method, comprising the following steps:
Step S1: video flowing broadcasts when the broadcast state logging modle of each user terminal records user's viewing live streaming in real time
Put status information;The broadcast state information of record is assembled into JSON format, and BASE64 coding is carried out to JSON character string;It will
Broadcast state information reporting after coding gives live streaming Platform Server, is transferred to step S2.
Step S2: the broadcast state information that the caching preprocessing module of Platform Server reports each user terminal is broadcast live
It is cached and is pre-processed (Uniform data format), be transferred to step S3.
Specifically, the detailed process that caching preprocessing module is cached are as follows: the broadcasting that each user terminal is reported
The JSON character string of status information carries out BASE64 decoding, abandons undesirable broadcast state information.Wherein, it does not meet and wants
The broadcast state information asked includes: that the illegal broadcast state information of video stream mode, User ID do not meet for empty or User ID
The broadcast state information of data field type, the broadcast state information of timestamp format error and type of user terminal mark
Illegal broadcast state information etc..
Also, the data format after broadcast state information is preprocessed is as follows:
Step S3: the timing of caching preprocessing module will cache and pretreated all broadcast state information are with several data
The form of piece is sent to distributed real-time computing module;Distributed computing module in real time is by each data slice received according to Hash
Strategy distributes to a specified real-time computational submodule, is transferred to step S4.
Preprocessing module timing is cached when practical operation, in step S3 will caching and pretreated all broadcast state letters
Breath is sent to distributed real-time computing module in the form of several data slices, specifically includes following operation: caching preprocessing module
Current cache and pretreated all broadcast state information are sent to distributed real-time computing module every 1 second, every time
Broadcast state information is combined into several data slices less than or equal to 1M when transmission to send, i.e., each data slice is by least one
A complete broadcast state information composition, and the data slice size formed is less than or equal to 1M.Such as: the broadcast state of current cache
There are three information has altogether, size is respectively that 0.3M, 0.4M and 0.5M can broadcast two of 0.3M, 0.4M when then this time sending
It puts status information and forms a data slice, then the broadcast state information of 0.5M is formed into another data slice;Finally by the two
Data slice is sent to distributed real-time computing module together.
Further, distributed computing module in real time distributes each data slice received according to Hash strategy in step S3
To a specified real-time computational submodule, specifically include following operation: distributed computing module in real time is each data slice point
With a unique ID number, by the ID number according to the number modulus of real-time computational submodule, the remainder of acquisition then corresponds to specified
The ID number of real-time computational submodule;Data slice is distributed to the real-time computational submodule of corresponding ID number.In the present invention, to data slice
The real-time computational submodule to be reported is selected by Hash strategy, in order to improve the water of distributed computing module in real time
Flat extended capability allows distributed computing module in real time accordingly to increase and decrease real-time meter according to the scale of data volume to be processed
The number of operator module.
Step S4: each computational submodule in real time parses the broadcast state information in data slice, according to parsing
The identification code of broadcast state information judges whether the broadcast state information is effective, if effective, is then transferred to step S5;Otherwise, directly
It connects and abandons the broadcast state information, terminate.
Wherein, judging the broadcast state information, effectively whether detailed process is as follows: to the identification in broadcast state information
Code be decrypted, take-off time stamp and terminal device ID, respectively checking time stamp whether in the reasonable scope (i.e. timestamp with work as
Whether the time difference of preceding server in one minute), terminal device ID whether meet whether specification (verifies terminal device ID again
Meet the create-rule of identification code);If above-mentioned verification passes through, determine that the broadcast state information is effective, otherwise, it is determined that
It is invalid.
Step S5: real-time computational submodule verifies the video stream mode of the broadcast state information, if being verified,
Then the User ID for the broadcast state information being verified is added in the corresponding any active ues collection fragment of current time, is turned
Enter step S6;If verifying does not pass through, the broadcast state information is directly abandoned, is terminated.
Wherein, verified that detailed process is as follows to the video stream mode of the broadcast state information: parsing, which obtains, to play
Video stream mode in status information, judges whether it meets the feature of normal play, if meeting, decision verification passes through;If
It does not meet, then decision verification does not pass through.Specifically, video flowing state meets the feature of normal play are as follows: must have PLAY first;
Secondly both Buffer.Full or Buffer.Empty be alternately present, or secondly only Buffer.Full or
Buffer.Empty one occurs.
Step S6: any active ues integrate functional module using the specified active calculating period as the period, periodically by current time
Corresponding any active ues collection fragment is updated into the time wheel disc created, is terminated.
Specifically, using the specified active calculating period as the period, periodically by the corresponding any active ues collection of current time
Fragment is updated into the time wheel disc created, and concrete operations are as follows:
Step S601: every any active ues collection after the specified active calculating period, in time wheel disc in each slot
Fragment moves forward a lattice (in the present invention, definition is mobile for Forward to head of the queue along clockwise direction) to head of the queue, at this point, being located at head of the queue
Any active ues collection fragment in slot is moved out of and destroys, and the slot positioned at tail of the queue is sky, is transferred to step S602;
Step S602: the corresponding any active ues collection fragment of current time is updated in the slot of tail of the queue, step is transferred to
S603;
Step S603: by the pointer on time wheel disc to head of the queue move forward a lattice.
The present invention is not limited to the above-described embodiments, for those skilled in the art, is not departing from
Under the premise of the principle of the invention, several improvements and modifications can also be made, these improvements and modifications are also considered as protection of the invention
Within the scope of.
The content being not described in detail in this specification belongs to the prior art well known to professional and technical personnel in the field.