# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

How does the time work on the shard ?

Id:
time.dxt,v 1.2 2001/10/30 14:14:45 lecroart Exp

Author:
Vianney Lecroart
Date:
Updated November 30, 2001

Introduction

In the NeL library, there's a class named CTime in the misc module (time_nl.h). This class encapsulates time functions provided by the OS.

The CUniTime class in the net module of NeL provides high level functions to get and set the universal time (unitime.h).

Time

For example, the getSecondsSince1970() method returns the number of seconds since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock. This value is computer dependant. This value is the same only if computers are synchronized (with NTP for example).

getLocalTime() returns a time in millisecond. It is used to time a function or compute the frame rate. This value is different on each machine and the update frequency is OS dependant but should be greater than 100Hz.

getPerformanceTime() returns a number of ticks. Presently it works only on Windows ; on other systems, it'll return 0. This function is used to get a very accurate value, to monitor a piece of code for example. You can use ticksToSecond() to convert this tick value into seconds.

Universal Time

Warning:
DEPRECATED
The universal time is the basis of time in a NeL system. This value is the same on all computers and is used in all services and clients to date events. This value is a sint64 (TTime type) containing the number of milliseconds since the creation of the virtual universe.

The Time Service stores this value in a file and centralizes time requests from other services.

getUniTime() returns the current universal time but before calling this method the class must be initialized and synchronized

There are 2 different ways to synchronize this universal time:

  • in the case of a service in the shard:
All servers that will run services must synchronize their clock with NTP. If you don't do that, services will not run. Services are synchronized automatically at startup and are resynchronized every hour to avoid accumulation errors. So, there's nothing to add in your code for a service to get the universal time.

  • in the case of a client:
There are 2 methods in the class CUniTime, one that you have to call on the client part (syncUniTimeFromServer()) and another one in the front-end service (installServer()).

How it works ?

Warning:
DEPRECATED
We use 2 different algorithms depending of the type the connection between the 2 programs.

  • in the case of a service in the shard:
All servers are synchronized with NTP so the getSecondsSince1970() method returns the same value at the same time on 2 different servers. When a service when to synchronize his universal time, it sends a request to the Time Service. The Time Service sends back a message that contains 2 values: the value returns by the getSecondsSince1970() method and the value returns by the getUniTime() method. When the service receives this message, it computes the new universal time with the 2 values in the message.

  • in case of a client:
We actually use a very simple algorithm to synchronize the universal time across Internet. The client makes several requests for the univeral time to the front-end service, and, according to the ping, it will deduce the current universal time.

For more information, take a look at time_nl.h and unitime.h.