Browse Source

[2136] Updated not to calculate next timing based on current timestamp in every
polling

Naoki Kambe 12 years ago
parent
commit
0abcaf5cdd
1 changed files with 10 additions and 6 deletions
  1. 10 6
      src/bin/stats/stats.py.in

+ 10 - 6
src/bin/stats/stats.py.in

@@ -245,9 +245,8 @@ class Stats:
             seconds"""
             seconds"""
             # backup original timeout
             # backup original timeout
             orig_timeout = self.cc_session.get_timeout()
             orig_timeout = self.cc_session.get_timeout()
-            # set config['poll-interval'] * 1000 (milliseconds) to
-            # timeout of cc-sesson
-            self.cc_session.set_timeout(self.get_interval()*1000)
+            # set cc-session timeout to half of a second(500ms)
+            self.cc_session.set_timeout(500)
             try:
             try:
                 answer, env = self.cc_session.group_recvmsg(nonblock)
                 answer, env = self.cc_session.group_recvmsg(nonblock)
                 self.mccs.check_command_without_recvmsg(answer, env)
                 self.mccs.check_command_without_recvmsg(answer, env)
@@ -260,9 +259,14 @@ class Stats:
             self.running = True
             self.running = True
             while self.running:
             while self.running:
                 _check_command()
                 _check_command()
-                if self.get_interval() > 0 and get_timestamp() >= self.next_polltime:
-                    # update the next polling timestamp
-                    self.next_polltime = get_timestamp() + self.get_interval()
+                now = get_timestamp()
+                if self.get_interval() > 0 and now >= self.next_polltime:
+                    intval = self.get_interval()
+                    # decide the next polling timestamp
+                    self.next_polltime += intval
+                    # adjust next time
+                    if self.next_polltime < now:
+                        self.next_polltime = now
                     self.do_polling()
                     self.do_polling()
         finally:
         finally:
             self.mccs.send_stopping()
             self.mccs.send_stopping()