-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: Sleeping In

Среда, 03 Июня 2015 г. 13:30 + в цитатник

Rebecca inherited some code thats responsible for gathering statistical data from network interface. It was original written a decade ago by one of those developers who wanted to make certain their influence was felt long after they left the company.

The code was supposed to write to one of two log files: a quick log, with 2-second resolution (but only for the last minutes data), and a full log, with 1-minute resolution.

Unfortunately, it would often fail to do anything with the full log. Frustrated that this code- which had lived in a shipping product for over a decade- was so unreliable, Rebecca dug in to see what the problem was.

#define FULL_SAMPLE_DELAY 60

void dostats(FILE *quicklog, FILE* mainlog) {
       //[code omitted for brevity]
        while(!done) {  
                sleep(2);
                if(!(times.now.t.tv_sec % FULL_SAMPLE_DELAY)) {
                        // main samples
                        stats.save(mainlog, times);
                }
                else {
                        // quick samples 
                        quickstats.summarise(quicklog, quickstats_top_n);
                }
        }
}

Rebeccas predecessor had the good sense to use sleep() to keep the loop from spinning the CPU, but made one major error: he assumed that calling quickstats.summarise took no time . Even if the loop started at exactly the right time, the amount of time spent executing quickstats.summarise guaranteed that eventually, the current time wouldnt line up with an even minute, and the full log would become unreliable.



[Advertisement] Release! is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped!

http://thedailywtf.com/articles/sleeping-in

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку