Class: LogGenerator::Executors
- Inherits:
-
Object
- Object
- LogGenerator::Executors
- Defined in:
- lib/apache-loggen/base.rb
Overview
Windowsだと割り込みが55msや10msだったりとするので100msごとに処理するように。 汚いソースになっちゃった・・。 MultimediaTimer使えばいいんだけど、めんどくさ。
Constant Summary collapse
- FIXED_RATE =
100
Class Method Summary collapse
Class Method Details
.exec(config) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/apache-loggen/base.rb', line 236 def self.exec(config) rate_per_sec = config[:rate] display = config[:progress] limited = rate_per_sec > 0 if limited then mspr = 1000.0 / rate_per_sec # ms per rec. rate = rate_per_sec.to_f / (1000 / FIXED_RATE) # rec per 100ms end start_time = Time.now time = last_display = Time.now count = 0 total_count = 0 while true do break unless yield({ :start_time => start_time, :total_count => total_count, :elapsed_time => (Time.now - start_time).round, }) total_count += 1 count += 1 if limited && count >= rate then spent = ((Time.now - time) * 1000).round sleep_ms = mspr - spent sleep(sleep_ms / 1000.0) if sleep_ms > 0 time = Time.now count = 0 end if display then if Time.now - last_display >= 1.0 then $stderr.printf("\r%d[rec] %.2f[rec/s]", total_count, total_count / (Time.now - start_time + 0.001)) last_display = Time.now end end end end |