Ignore:
Timestamp:
06/10/11 08:52:28 (13 years ago)
Author:
lyard
Message:
Moved monitoring thread to main thread. Added timeout config
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/dataLogger.cc

    r10968 r10971  
    221221    ///run numbers
    222222    list<RunNumberType> fRunNumber;
     223    ///old run numbers time-out delay (in minutes)
     224    long fRunNumberTimeout;
    223225    ///previous run number. to check if changed while logging
    224226    int fPreviousRunNumber;
     
    236238    ///full name of the nightly report file
    237239    string fFullNightlyReportFileName;
    238     ///variables for computing statistics
    239     DataLoggerStats fStatVar;
    240240    ///variable to track when the statistic were last calculated
    241241    double fPreviousStatsUpdateTime;
    242242    double fPreviousOldRunNumberCheck;
    243     ///mutex to make sure that the Stats are not accessed while updating
    244     mutex fStatsMutex;
    245243    ///boolean to know whether we should close and reopen daily files or not
    246244    bool fDailyFileDayChangedAlready;
     
    266264    static const char* fStartStopOpenedFiles;
    267265    static const char* fStartStopNumSubsAndFits;
     266    static const char* fSetRunTimeOutDelay;
    268267private:
    269268    /***************************************************
     
    315314    void ServicesMonitoring();
    316315    inline void NotifyOpenedFile(const string &name, int type, DimDescribedService* service);
     316    ///variables for computing statistics
     317    DataLoggerStats fStatVar;
     318    ///mutex to make sure that the Stats are not accessed while updating
     319//    mutex fStatsMutex;
    317320    ///services notification thread
    318     boost::thread fMonitoringThread;
     321//    boost::thread fMonitoringThread;
    319322    ///end of the monitoring
    320     bool fContinueMonitoring;
     323//    bool fContinueMonitoring;
    321324    ///stores the size of each file that is or was open
    322325    map<string, long> fFileSizesMap;
     
    329332    DimDescribedService* fOpenedRunFiles;
    330333    DimDescribedService* fNumSubAndFits;
     334    DimDescribedService* fStatsMonitoring;
    331335    NumSubAndFitsType fNumSubAndFitsData;
    332336    ///Small function for calculating the total size written so far
     
    351355    int SetOpenedFilesOnOff(const Event& evt);
    352356    int SetNumSubsAndFitsOnOff(const Event& evt);
     357    int SetRunTimeoutDelay(const Event& evt);
    353358
    354359    ///boolean to prevent DIM update while desctructing the dataLogger
     
    772777bool DataLogger::calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting)
    773778{
    774     if (!isPrinting)
    775         fStatsMutex.lock();
     779//mutex
     780//    if (!isPrinting)
     781//        fStatsMutex.lock();
    776782#ifdef HAVE_FITS
    777783    if (isPrinting)
     
    841847    statVar.sizeWritten -= fBaseSizeRun;
    842848
    843     if (!isPrinting)
    844         fStatsMutex.unlock();
     849//mutex
     850//    if (!isPrinting)
     851//        fStatsMutex.unlock();
    845852
    846853    return shouldWarn;
     
    865872const char* DataLogger::fStartStopOpenedFiles = "OPENED_FILES_SRVC";
    866873const char* DataLogger::fStartStopNumSubsAndFits = "NUM_SUBS_SRVC";
     874const char* DataLogger::fSetRunTimeOutDelay = "RUN_TIMEOUT";
    867875
    868876// --------------------------------------------------------------------------
     
    871879//
    872880//
     881/*
    873882void DataLogger::ServicesMonitoring()
    874883{
     
    911920        }
    912921}
    913 
     922*/
    914923// --------------------------------------------------------------------------
    915924//
     
    10151024     AddEvent(fStatsPeriod, "F", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
    10161025             (boost::bind(&DataLogger::SetStatsPeriod, this, _1))
    1017              ("Interval in which the data-logger statitistics service (STATS) is updated."
     1026             ("Interval in which the data-logger statistics service (STATS) is updated."
    10181027              "Interval[s]:Floating point value in seconds.");
    10191028
     
    10251034             (boost::bind(&DataLogger::SetNumSubsAndFitsOnOff, this, _1))
    10261035             ("Switch off the service which distributes information about the number of subscriptions and open files.");
     1036
     1037     AddEvent(fSetRunTimeOutDelay, "L:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun)
     1038             (boost::bind(&DataLogger::SetRunTimeoutDelay, this, _1))
     1039             ("Set the timeout delay for old run numbers.");
    10271040
    10281041     fDestructing = false;
     
    10341047     fPreviousStatsUpdateTime = Time().Mjd();
    10351048     fPreviousOldRunNumberCheck = Time().Mjd();
    1036      fContinueMonitoring = true;
    1037      fMonitoringThread = boost::thread(boost::bind(&DataLogger::ServicesMonitoring, this));
     1049     fPreviousSize = 0;
     1050
     1051     struct statvfs vfs;
     1052     if (!statvfs(fNightlyFilePath.c_str(), &vfs))
     1053         fStatVar.freeSpace = vfs.f_bsize*vfs.f_bavail;
     1054     else
     1055         fStatVar.freeSpace = -1;
     1056
     1057     fStatsMonitoring = new DimDescribedService(GetName() + "/STATS", "X:3", fStatVar, "Add description here");
     1058
     1059//mutex
     1060//     fContinueMonitoring = true;
     1061//     fMonitoringThread = boost::thread(boost::bind(&DataLogger::ServicesMonitoring, this));
    10381062     fBaseSizeNightly = 0;
    10391063     fBaseSizeRun = 0;
    10401064     fDailyFileDayChangedAlready = true;
     1065     fRunNumberTimeout = 1;
    10411066     if(fDebugIsOn)
    10421067     {
     
    10611086    fServiceSubscriptions.clear();
    10621087    //exit the monitoring loop
    1063     fContinueMonitoring = false;
    1064 
    1065     fMonitoringThread.join();
     1088//mutex
     1089//    fContinueMonitoring = false;
     1090//    fMonitoringThread.join();
    10661091    //clear any remaining run number (should remain only one)
    10671092     while (fRunNumber.size() > 0)
     
    11361161        fPreviousSize = fStatVar.sizeWritten;
    11371162        fPreviousStatsUpdateTime = cTime.Mjd();
    1138     }
    1139     if ((cTime.Mjd() - fPreviousOldRunNumberCheck)*24*60*60 > 10.0)
    1140     {
    1141         while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::time_duration(0,0,10,0))
     1163        //update the service. No need to check if data has been written, because some must have been, otherwise we would not have hit this piece of code
     1164        fStatsMonitoring->updateService();
     1165
     1166        if(fDebugIsOn)
     1167        {
     1168            ostringstream str;
     1169            str << "Size written: " << fStatVar.sizeWritten/1000 << " kB; writing rate: ";
     1170            str << fStatVar.writingRate/1000 << " kB/s; free space: ";
     1171            str << fStatVar.freeSpace/(1000*1000) << " MB";
     1172            Debug(str);
     1173        }
     1174    }
     1175    if ((cTime.Mjd() - fPreviousOldRunNumberCheck)*24*60 >= fRunNumberTimeout)
     1176    {
     1177        while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::minutes(fRunNumberTimeout))
    11421178        {
    11431179             RemoveOldestRunNumber();
     
    14871523        str << " <none>";
    14881524    Message(str);
     1525    //timeout value
     1526    str.str("");
     1527    str << "Timeout delay for old run numbers: " << fRunNumberTimeout << " minute(s)";
     1528    Message(str);
    14891529
    14901530    //print all the open files.
     
    16631703        ostringstream str;
    16641704        str << "Number of subscriptions service mode is now " << fNumSubAndFitsIsOn;
     1705        Message(str);
     1706    }
     1707    return GetCurrentState();
     1708}
     1709// --------------------------------------------------------------------------
     1710//
     1711//! set the timeout delay for old run numbers
     1712//! @param evt
     1713//!        the current event. contains the timeout delay long value
     1714//! @returns
     1715//!        the new state. Which, in that case, is the current state
     1716//!
     1717int DataLogger::SetRunTimeoutDelay(const Event& evt)
     1718{
     1719    const long backupTimeout = fRunNumberTimeout;
     1720    fRunNumberTimeout = evt.GetXtra();
     1721
     1722    if (fRunNumberTimeout == 0)
     1723    {
     1724        fRunNumberTimeout = backupTimeout;
     1725        Error("timeout delays for old run numbers must be greater than 0. Ignored.");
     1726        return GetCurrentState();
     1727    }
     1728
     1729    if (fRunNumberTimeout == backupTimeout)
     1730        Warn("Warning: given timeout for old run numbers is same value as previous one");
     1731    else
     1732    {
     1733        ostringstream str;
     1734        str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout;
    16651735        Message(str);
    16661736    }
     
    23142384    fBlackList.insert("DIS_DNS/");
    23152385
     2386    //set the black list
    23162387    if (conf.Has("block"))
    23172388    {
     
    23212392    }
    23222393
     2394    //set the white list
    23232395    if (conf.Has("allow"))
    23242396    {
     
    23322404        const vector<string> vec = conf.Get<vector<string>>("group");
    23332405        fGrouping.insert(vec.begin(), vec.end());
     2406    }
     2407
     2408    //set the old run numbers timeout delay
     2409    if (conf.Has("runtimeout"))
     2410    {
     2411        const long timeout = conf.Get<long>("runtimeout");
     2412        if (timeout != 0)
     2413            fRunNumberTimeout = timeout;
     2414        else
     2415            Error("Time out delay for old run numbers should be greater than 0 minute");
    23342416    }
    23352417    return true;
     
    24752557        ("debug",   po_bool(),      "Debug mode. Print clear text of received service reports to log-stream")
    24762558        ("group,g", vars<string>(), "Grouping of services into a single run-Fits")
     2559        ("runtimeout", var<long>(), "Time out delay for old run numbers")
    24772560        ;
    24782561
Note: See TracChangeset for help on using the changeset viewer.