garru-distributed_logreader 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/distributed_logreader.gemspec +2 -2
- data/lib/distributed_logreader/distributed_log_reader/scribe_reader.rb +1 -1
- data/lib/distributed_logreader/distributed_log_reader.rb +2 -6
- data/lib/distributed_logreader/distributer/simple_thread_pool.rb +11 -4
- data/lib/distributed_logreader/log_reader.rb +11 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{distributed_logreader}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.6.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Gary Tsang"]
|
9
|
-
s.date = %q{2009-08-
|
9
|
+
s.date = %q{2009-08-06}
|
10
10
|
s.email = %q{gary@garru.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -5,7 +5,7 @@ module DLogReader
|
|
5
5
|
def initialize(filename, backupdir, worker, num_threads = 10)
|
6
6
|
super(filename, worker, num_threads)
|
7
7
|
self.selector = RotatingLog.new
|
8
|
-
self.selector.ignore_conditions << lambda{|x| x.match(/scribe_stats/)}
|
8
|
+
self.selector.ignore_conditions << lambda{|x| !x.match(/scribe_stats/).nil?}
|
9
9
|
self.archiver = DateDir.new(backupdir)
|
10
10
|
end
|
11
11
|
|
@@ -17,14 +17,10 @@ module DLogReader
|
|
17
17
|
def process
|
18
18
|
pre_process
|
19
19
|
|
20
|
-
$dlog_logger.info("Started
|
20
|
+
$dlog_logger.info("Started #{log_file}:")
|
21
21
|
lines_processed = 0
|
22
22
|
@log_reader = LogReader.new(log_file) do |line|
|
23
|
-
|
24
|
-
self.distributer.process(line)
|
25
|
-
rescue Exception => e
|
26
|
-
$dlog_logger.warn("Exception in processing thread #{log_file}:#{log_file.pos} -- #{line} -- #{e.message}")
|
27
|
-
end
|
23
|
+
self.distributer.process(line)
|
28
24
|
lines_processed += 1
|
29
25
|
end
|
30
26
|
@log_reader.run
|
@@ -2,18 +2,21 @@ require 'thread'
|
|
2
2
|
|
3
3
|
module DLogReader
|
4
4
|
class SimpleThreadPool
|
5
|
-
attr_accessor :num_threads, :worker, :thread_pool, :queue
|
6
|
-
|
7
|
-
def initialize(worker, num_threads = 10)
|
5
|
+
attr_accessor :num_threads, :worker, :thread_pool, :queue, :max_queue_size
|
6
|
+
def initialize(worker, num_threads = 5)
|
8
7
|
self.worker = worker
|
9
8
|
self.num_threads = num_threads
|
10
9
|
self.queue = Queue.new
|
10
|
+
self.max_queue_size = 100
|
11
11
|
num_threads.times do
|
12
12
|
create_thread
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def process(line)
|
17
|
+
while(queue.size > self.max_queue_size)
|
18
|
+
sleep(0.1)
|
19
|
+
end
|
17
20
|
self.queue << line
|
18
21
|
end
|
19
22
|
|
@@ -28,7 +31,11 @@ protected
|
|
28
31
|
Thread.new do
|
29
32
|
loop do
|
30
33
|
line = self.queue.pop
|
31
|
-
|
34
|
+
begin
|
35
|
+
self.worker.call(line)
|
36
|
+
rescue Exception => e
|
37
|
+
$dlog_logger.warn("Exception in processing thread #{line} -- #{e.message}")
|
38
|
+
end
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
@@ -15,10 +15,18 @@ module DLogReader
|
|
15
15
|
f = File.open(filename, "r+")
|
16
16
|
load_saved_state(f)
|
17
17
|
raise IOError.new("File is locked") unless f.flock(File::LOCK_EX | File::LOCK_NB)
|
18
|
-
f.
|
19
|
-
|
18
|
+
unless f.eof?
|
19
|
+
line_count = 0
|
20
|
+
f.each_line do |line|
|
21
|
+
@b.call(line)
|
22
|
+
line_count += 1
|
23
|
+
if (line_count % 100 == 0)
|
24
|
+
$dlog_logger.info( "#{Time.now.to_s} #{filename}: Processed (#{line_count}) lines")
|
25
|
+
save_state(f)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
save_state(f)
|
20
29
|
end
|
21
|
-
save_state(f)
|
22
30
|
f.flock(File::LOCK_UN)
|
23
31
|
end
|
24
32
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garru-distributed_logreader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary Tsang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|