fairy 0.6.0 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. data/Makefile +1 -0
  2. data/bin/fairy +35 -5
  3. data/ext/extconf.rb +3 -0
  4. data/ext/fairy.c +180 -0
  5. data/ext/fairy.h +94 -0
  6. data/ext/fiber_mon.h +32 -0
  7. data/ext/fixnum-buffer.c +483 -0
  8. data/ext/p-group-by.c +529 -0
  9. data/ext/p-xgroup-by.c +467 -0
  10. data/ext/simple-hash.c +44 -0
  11. data/ext/string-buffer.c +286 -0
  12. data/ext/xmarshaled-queue.c +699 -0
  13. data/ext/xsized-queue.c +528 -0
  14. data/ext/xthread.h +65 -0
  15. data/fairy.gemspec +5 -2
  16. data/lib/fairy.rb +10 -1
  17. data/lib/fairy/client/group-by.rb +57 -2
  18. data/lib/fairy/client/here.rb +2 -1
  19. data/lib/fairy/controller.rb +25 -4
  20. data/lib/fairy/master.rb +17 -3
  21. data/lib/fairy/master/c-basic-group-by.rb +4 -2
  22. data/lib/fairy/master/c-cat.rb +3 -2
  23. data/lib/fairy/master/c-direct-product.rb +5 -3
  24. data/lib/fairy/master/c-filter.rb +5 -3
  25. data/lib/fairy/master/c-group-by.rb +13 -0
  26. data/lib/fairy/master/c-junction.rb +3 -2
  27. data/lib/fairy/master/c-seg-join.rb +3 -1
  28. data/lib/fairy/master/c-seg-shuffle.rb +3 -2
  29. data/lib/fairy/master/c-seg-split.rb +1 -1
  30. data/lib/fairy/master/c-seg-zip.rb +3 -1
  31. data/lib/fairy/master/c-sort.rb +7 -2
  32. data/lib/fairy/master/c-wc.rb +5 -3
  33. data/lib/fairy/node.rb +13 -2
  34. data/lib/fairy/node/p-barrier.rb +1 -1
  35. data/lib/fairy/node/p-basic-group-by.rb +22 -12
  36. data/lib/fairy/node/p-direct-product.rb +4 -2
  37. data/lib/fairy/node/p-filter.rb +8 -7
  38. data/lib/fairy/node/p-find.rb +2 -1
  39. data/lib/fairy/node/p-group-by.rb +17 -6
  40. data/lib/fairy/node/p-inject.rb +3 -2
  41. data/lib/fairy/node/p-output-file.rb +1 -1
  42. data/lib/fairy/node/p-seg-join.rb +2 -1
  43. data/lib/fairy/node/p-seg-zip.rb +2 -1
  44. data/lib/fairy/node/p-single-exportable.rb +3 -1
  45. data/lib/fairy/node/p-sort.rb +4 -2
  46. data/lib/fairy/node/p-task.rb +1 -1
  47. data/lib/fairy/node/p-wc.rb +5 -2
  48. data/lib/fairy/processor.rb +25 -18
  49. data/lib/fairy/share/block-source.rb +12 -2
  50. data/lib/fairy/share/conf.rb +35 -5
  51. data/lib/fairy/share/hash-simple-hash.rb +1 -1
  52. data/lib/fairy/share/log.rb +11 -4
  53. data/lib/fairy/share/pool-dictionary.rb +2 -1
  54. data/lib/fairy/share/port-marshaled-queue.rb +8 -1
  55. data/lib/fairy/share/port.rb +55 -45
  56. data/lib/fairy/share/reference.rb +2 -1
  57. data/lib/fairy/share/varray.rb +3 -1
  58. data/lib/fairy/share/vfile.rb +4 -2
  59. data/lib/fairy/version.rb +1 -1
  60. data/sample/sort.rb +69 -3
  61. data/spec/fairy8_spec.rb +1 -1
  62. data/test/testc.rb +380 -2
  63. data/tools/cap_recipe/Capfile +3 -3
  64. data/tools/fairy_conf_wizard.rb +375 -0
  65. data/tools/fairy_perf_graph.rb +15 -3
  66. data/tools/git-tag +1 -0
  67. data/tools/log-analysis.rb +59 -11
  68. metadata +33 -34
  69. data/ext/simple_hash/extconf.rb +0 -4
  70. data/ext/simple_hash/simple_hash.c +0 -42
@@ -2,6 +2,7 @@
2
2
  #
3
3
  # Copyright (C) 2007-2010 Rakuten, Inc.
4
4
  #
5
+ require "xthread"
5
6
 
6
7
  module Fairy
7
8
  class PoolDictionary
@@ -9,7 +10,7 @@ module Fairy
9
10
  def initialize
10
11
  @pool = {}
11
12
  @pool_mutex = Mutex.new
12
- @pool_cv = ConditionVariable.new
13
+ @pool_cv = XThread::ConditionVariable.new
13
14
  end
14
15
 
15
16
  attr_reader :pool_mutex
@@ -2,12 +2,13 @@
2
2
  #
3
3
  # Copyright (C) 2007-2010 Rakuten, Inc.
4
4
  #
5
+ require "xthread"
5
6
 
6
7
  module Fairy
7
8
 
8
9
  class MarshaledQueue
9
10
 
10
- def initialize(policy, queues_mon = Monitor.new, queues_cv = queues_mon.new_cond)
11
+ def initialize(policy, queues_mon = XThread::Monitor.new, queues_cv = queues_mon.new_cond)
11
12
  @policy = policy
12
13
 
13
14
  @chunk_size = CONF.MARSHAL_QUEUE_CHUNK_SIZE
@@ -319,7 +320,10 @@ module Fairy
319
320
 
320
321
  def store_2ndmemory(ary)
321
322
  open_2ndmemory do |io|
323
+ # log解析で使いたいときはデコメントする
324
+ # Log::debug(self, "START M.STORE")
322
325
  Marshal.dump(ary, io)
326
+ # Log::debug(self, "FINISH M.STORE")
323
327
  end
324
328
  end
325
329
 
@@ -330,9 +334,12 @@ module Fairy
330
334
  end
331
335
 
332
336
  def restore_2ndmemory(buf)
337
+ # log解析で使いたいときはデコメントする
338
+ # Log::debug(self, "START M.RESTORE")
333
339
  io = buf.open
334
340
  queue = Marshal.load(io)
335
341
  buf.close!
342
+ # Log::debug(self, "FINISH M.RESTORE")
336
343
  queue
337
344
  end
338
345
 
@@ -5,6 +5,8 @@
5
5
 
6
6
  require "forwardable"
7
7
 
8
+ require "xthread"
9
+
8
10
  require "fiber-mon"
9
11
  require "fairy/share/fast-tempfile.rb"
10
12
 
@@ -80,6 +82,7 @@ module Fairy
80
82
  end
81
83
 
82
84
  Log::debug(self, "Using Buffer: #{@queue.class}")
85
+ Log::debug(self, "Inspect: #{@queue.inspect}")
83
86
 
84
87
  @log_import_ntimes_pop = CONF.LOG_IMPORT_NTIMES_POP
85
88
  @log_callback_proc = nil
@@ -88,7 +91,7 @@ module Fairy
88
91
 
89
92
  @no = nil
90
93
  @no_mutex = Mutex.new
91
- @no_cv = ConditionVariable.new
94
+ @no_cv = XThread::ConditionVariable.new
92
95
 
93
96
  @key = nil
94
97
 
@@ -321,39 +324,44 @@ module Fairy
321
324
  END_OF_STREAM = :END_OF_STREAM
322
325
 
323
326
  ExportMonitor = FiberMon.new
324
- ExportMonitor.start
327
+ #ExportMonitor.start
325
328
 
326
329
  def initialize(policy = nil)
327
-
330
+
328
331
  @queuing_policy = policy
329
332
  @queuing_policy ||= CONF.POSTQUEUING_POLICY
330
333
  @max_chunk = CONF.POSTQUEUE_MAX_TRANSFER_SIZE
331
334
 
332
335
  @STR_TRANSFAR = CONF.TRANSFAR_MARSHAL_STRING_ARRAY_OPTIMIZE
336
+ if @queuing_policy.kind_of?(Hash) &&
337
+ @queuing_policy[:transfar_marshal_string_array_optimize]
338
+ @STR_TRANSFAR = @queuing_policy[:transfar_marshal_string_array_optimize]
339
+ end
333
340
 
334
341
  # @output_buf = []
335
342
  # @output_buf_mutex = Mutex.new
336
- # @output_buf_cv = ConditionVariable.new
343
+ # @output_buf_cv = XThread::ConditionVariable.new
337
344
 
338
345
  @output = nil
339
346
  @output_mutex = Mutex.new
340
- @output_cv = ConditionVariable.new
347
+ @output_cv = XThread::ConditionVariable.new
341
348
 
342
349
  @njob_id = nil
343
350
 
344
351
  @no = nil
345
352
  @no_mutex = Mutex.new
346
- @no_cv = ConditionVariable.new
353
+ @no_cv = XThread::ConditionVariable.new
347
354
 
348
355
  @key = nil
349
356
 
350
357
  @status = nil
351
358
  @status_mutex = Mutex.new
352
- @status_cv = ConditionVariable.new
359
+ @status_cv = XThread::ConditionVariable.new
353
360
 
354
361
  @export_mon = ExportMonitor
355
- @pop_cv = @export_mon.new_cv
356
- @export_cv = @export_mon.new_cv
362
+ @export_mx = @export_mon.new_mon
363
+ @pop_cv = @export_mx.new_cv
364
+ @export_cv = @export_mx.new_cv
357
365
 
358
366
  case @queuing_policy
359
367
  when Hash
@@ -366,7 +374,6 @@ module Fairy
366
374
  end
367
375
 
368
376
  Log::debug(self, "Using Buffer: #{@queue.class}")
369
-
370
377
  end
371
378
 
372
379
  def log_id
@@ -464,11 +471,11 @@ module Fairy
464
471
  end
465
472
 
466
473
  def fib_pop
467
- @export_mon.synchronize do
474
+ @export_mx.synchronize do
468
475
  e = nil
469
476
  #@export_mon.entry{e = @queue.pop; @pop_cv.signal}
470
477
  Thread.start do
471
- @export_mon.synchronize do
478
+ @export_mx.synchronize do
472
479
  e = @queue.pop
473
480
  @pop_cv.signal
474
481
  end
@@ -479,11 +486,11 @@ module Fairy
479
486
  end
480
487
 
481
488
  def fib_pop_all
482
- @export_mon.synchronize do
489
+ @export_mx.synchronize do
483
490
  e = nil
484
491
  #@export_mon.entry{e = @queue.pop; @pop_cv.signal}
485
492
  Thread.start do
486
- @export_mon.synchronize do
493
+ @export_mx.synchronize do
487
494
  e = @queue.pop_all
488
495
  @pop_cv.signal
489
496
  end
@@ -506,6 +513,7 @@ module Fairy
506
513
 
507
514
  def start_export0
508
515
  @export_mon.entry do
516
+ puts "AAAAAAAAAAAAAAAA:0"
509
517
  if bug49 = CONF.DEBUG_BUG49
510
518
  # BUG#49用
511
519
  Log::debug(self, "export START")
@@ -514,7 +522,7 @@ module Fairy
514
522
  end
515
523
  self.status = :EXPORT
516
524
 
517
- @export_mon.synchronize do
525
+ @export_mx.synchronize do
518
526
  # while (e = fib_pop) != END_OF_STREAM
519
527
  while (e = @queue.pop) != END_OF_STREAM
520
528
  if bug49
@@ -527,11 +535,11 @@ module Fairy
527
535
  begin
528
536
  if PORT_KEEP_IDENTITY_CLASS_SET[e.class]
529
537
  @output.asyncronus_send_with_callback(:push_keep_identity, e){
530
- @export_mon.synchronize{@export_cv.broadcast}
538
+ @export_mx.synchronize{@export_cv.broadcast}
531
539
  }
532
540
  else
533
541
  @output.asyncronus_send_with_callback(:push, e) {
534
- @export_mon.synchronize{@export_cv.broadcast}
542
+ @export_mx.synchronize{@export_cv.broadcast}
535
543
  }
536
544
  end
537
545
  @export_cv.wait
@@ -567,15 +575,16 @@ module Fairy
567
575
  def start_export
568
576
  Log::debug(self, "START EXPORT")
569
577
 
570
- unless @queue.respond_to?(:pop_all)
571
- return start_export0
572
- end
573
-
574
578
  if @queue.respond_to?(:pop_raw)
575
579
  return start_export_raw
576
580
  end
581
+
582
+ unless @queue.respond_to?(:pop_all)
583
+ return start_export0
584
+ end
577
585
 
578
586
  @export_mon.entry do
587
+ puts "AAAAAAAAAAAAAAAA:1"
579
588
  if bug49 = CONF.DEBUG_BUG49
580
589
  # BUG#49用
581
590
  Log::debug(self, "export key=#{@key}: START")
@@ -583,7 +592,7 @@ module Fairy
583
592
  mod = CONF.LOG_IMPORT_NTIMES_POP
584
593
  limit = mod
585
594
  end
586
- # @export_mon.synchronize do
595
+ # @export_mx.synchronize do
587
596
  while (pops = @queue.pop_all).last != END_OF_STREAM
588
597
  # while (pops = fib_pop_all).last != END_OF_STREAM
589
598
 
@@ -683,9 +692,9 @@ module Fairy
683
692
  if PORT_KEEP_IDENTITY_CLASS_SET[e.class]
684
693
  exports_elements_sub(elements, start, idx-1)
685
694
  sended = nil
686
- @export_mon.synchronize do
695
+ @export_mx.synchronize do
687
696
  @output.asynchronus_send_with_callback(:push_keep_identity, e){
688
- @export_mon.synchronize do
697
+ @export_mx.synchronize do
689
698
  sended = true
690
699
  @export_cv.broadcast
691
700
  end
@@ -707,10 +716,10 @@ module Fairy
707
716
  def exports_elements_sub(elements, start, last, max = @max_chunk)
708
717
  while last >= start
709
718
  len = [max, last - start + 1].min
710
- @export_mon.synchronize do
719
+ @export_mx.synchronize do
711
720
  sended = nil
712
721
  @output.asynchronus_send_with_callback(:push_buf, elements[start, len]){
713
- @export_mon.synchronize do
722
+ @export_mx.synchronize do
714
723
  sended = true
715
724
  @export_cv.broadcast
716
725
  end
@@ -727,10 +736,10 @@ module Fairy
727
736
  bigstr = elements[start, len].collect{|e|
728
737
  e.gsub(/[\\\t]/){|v| v == "\t" ? "\\t" : '\\\\'}
729
738
  }.join("\t")
730
- @export_mon.synchronize do
739
+ @export_mx.synchronize do
731
740
  sended = nil
732
741
  @output.asynchronus_send_with_callback(:push_strings, bigstr) {
733
- @export_mon.synchronize do
742
+ @export_mx.synchronize do
734
743
  sended = true
735
744
  @export_cv.broadcast
736
745
  end
@@ -740,12 +749,12 @@ module Fairy
740
749
  start += len
741
750
  end
742
751
  end
743
-
744
-
752
+
745
753
  def start_export_raw
746
754
  Log::debug(self, "START EXPORT(RAW MODE)")
747
755
 
748
756
  @export_mon.entry do
757
+ puts "AAAAAAAAAAAAAAAA:2"
749
758
  if bug49 = CONF.DEBUG_BUG49
750
759
  # BUG#49用
751
760
  Log::debug(self, "export key=#{@key}: START")
@@ -753,7 +762,7 @@ module Fairy
753
762
  mod = CONF.LOG_IMPORT_NTIMES_POP
754
763
  limit = mod
755
764
  end
756
- # @export_mon.synchronize do
765
+ # @export_mx.synchronize do
757
766
  while (raw = @queue.pop_raw) != END_OF_STREAM
758
767
  if bug49
759
768
  n += pops.size
@@ -794,10 +803,10 @@ module Fairy
794
803
  end
795
804
 
796
805
  def export_elements_raw(raw)
797
- @export_mon.synchronize do
806
+ @export_mx.synchronize do
798
807
  sended = nil
799
808
  @output.asynchronus_send_with_callback(:push_raw, raw) {
800
- @export_mon.synchronize do
809
+ @export_mx.synchronize do
801
810
  sended = true
802
811
  @export_cv.broadcast
803
812
  end
@@ -862,7 +871,8 @@ module Fairy
862
871
  # ここから, 後で要検討
863
872
  def status=(val)
864
873
  @status_mutex.synchronize do
865
- @status_cv.broadcast{@status = val}
874
+ @status = val
875
+ @status_cv.broadcast
866
876
  end
867
877
  end
868
878
 
@@ -888,12 +898,12 @@ module Fairy
888
898
  if queues_mon
889
899
  raise "OnMemoryQueueはfiberをサポートしていません"
890
900
  end
891
- Queue.new
901
+ XThread::Queue.new
892
902
  end
893
903
  end
894
904
 
895
905
  class PoolQueue
896
- def initialize(policy, queue_mon = Monitor.new, queue_cv = queue_mon.new_cond)
906
+ def initialize(policy, queue_mon = XThread::Monitor.new, queue_cv = queue_mon.new_cond)
897
907
  @policy = policy
898
908
 
899
909
  @queue_threshold = CONF.POOLQUEUE_POOL_THRESHOLD
@@ -951,7 +961,7 @@ module Fairy
951
961
 
952
962
  size = policy[:size]
953
963
  size ||= CONF.ONMEMORY_SIZEDQUEUE_SIZE
954
- @queue = SizedQueue.new(size)
964
+ @queue = XThread::SizedQueue.new(size)
955
965
  end
956
966
 
957
967
  def_delegator :@queue, :push
@@ -960,7 +970,7 @@ module Fairy
960
970
  OnMemorySizedQueue = SizedQueue
961
971
 
962
972
  class SizedPoolQueue<PoolQueue
963
- def initialize(policy, queue_mon = Monitor.new, queue_cv = queues_mon.new_cond)
973
+ def initialize(policy, queue_mon = XThread::Monitor.new, queue_cv = queues_mon.new_cond)
964
974
  super
965
975
  @max_size = policy[:size]
966
976
  @max_size ||= CONF.ONMEMORY_SIZEDQUEUE_SIZE
@@ -1007,7 +1017,7 @@ module Fairy
1007
1017
 
1008
1018
  class ChunkedPoolQueue
1009
1019
  # multi push threads single pop thread
1010
- def initialize(policy, queues_mon = Monitor.new, queues_cv = queues_mon.new_cond)
1020
+ def initialize(policy, queues_mon = XThread::Monitor.new, queues_cv = queues_mon.new_cond)
1011
1021
  @policy = policy
1012
1022
 
1013
1023
  @queue_threshold = CONF.POOLQUEUE_POOL_THRESHOLD
@@ -1081,7 +1091,7 @@ module Fairy
1081
1091
  end
1082
1092
 
1083
1093
  class ChunkedSizedPoolQueue<ChunkedPoolQueue
1084
- def initialize(policy, queues_mon = Monitor.new, queues_cv = queues_mon.new_cond)
1094
+ def initialize(policy, queues_mon = XThread::Monitor.new, queues_cv = queues_mon.new_cond)
1085
1095
  super
1086
1096
  @max_size = policy[:size]
1087
1097
  @max_size ||= CONF.ONMEMORY_SIZEDQUEUE_SIZE
@@ -1128,7 +1138,7 @@ module Fairy
1128
1138
  end
1129
1139
 
1130
1140
  class FileBufferdQueue
1131
- def initialize(policy, queue_mon = Monitor.new, queue_cv = queue_mon.new_cond)
1141
+ def initialize(policy, queue_mon = XThread::Monitor.new, queue_cv = queue_mon.new_cond)
1132
1142
 
1133
1143
  @policy = policy
1134
1144
  @threshold = policy[:threshold]
@@ -1249,7 +1259,7 @@ module Fairy
1249
1259
  end
1250
1260
 
1251
1261
  class ChunkedFileBufferdQueue
1252
- def initialize(policy, queue_mon = Monitor.new, queue_cv = queue_mon.new_cond)
1262
+ def initialize(policy, queue_mon = XThread::Monitor.new, queue_cv = queue_mon.new_cond)
1253
1263
  @policy = policy
1254
1264
  @threshold = policy[:threshold]
1255
1265
  @threshold ||= CONF.FILEBUFFEREDQUEUE_THRESHOLD
@@ -1379,7 +1389,7 @@ module Fairy
1379
1389
  end
1380
1390
 
1381
1391
  class SortedQueue
1382
- def initialize(policy, queue_mon = Monitor.new, queue_cv = queue_mon.new_cond)
1392
+ def initialize(policy, queue_mon = XThread::Monitor.new, queue_cv = queue_mon.new_cond)
1383
1393
  @policy = policy
1384
1394
 
1385
1395
  @pool_threshold = policy[:pool_threshold]
@@ -1540,7 +1550,7 @@ module Fairy
1540
1550
  end
1541
1551
 
1542
1552
  class OnMemorySortedQueue
1543
- def initialize(policy, queue_mon = Monitor.new, queue_cv = queue_mon.new_cond)
1553
+ def initialize(policy, queue_mon = XThread::Monitor.new, queue_cv = queue_mon.new_cond)
1544
1554
  @policy = policy
1545
1555
 
1546
1556
  @pool_threshold = policy[:pool_threshold]
@@ -1598,7 +1608,7 @@ module Fairy
1598
1608
  end
1599
1609
 
1600
1610
  class SortedQueue1<OnMemorySortedQueue
1601
- def initialize(policy, queue_mon = Monitor.new, queue_cv = queue_mon.new_cond)
1611
+ def initialize(policy, queue_mon = XThread::Monitor.new, queue_cv = queue_mon.new_cond)
1602
1612
  super
1603
1613
 
1604
1614
  @threshold = policy[:threshold]
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require "thread"
7
+ require "xthread"
7
8
 
8
9
  module Fairy
9
10
  class Reference
@@ -13,7 +14,7 @@ module Fairy
13
14
  def initialize
14
15
  @value = NULL_VALUE
15
16
  @value_mutex = Mutex.new
16
- @value_cv = ConditionVariable.new
17
+ @value_cv = XThread::ConditionVariable.new
17
18
  end
18
19
 
19
20
  def value
@@ -3,6 +3,8 @@
3
3
  # Copyright (C) 2007-2010 Rakuten, Inc.
4
4
  #
5
5
 
6
+ require "xthread"
7
+
6
8
  module Fairy
7
9
  class VArray
8
10
  include Enumerable
@@ -16,7 +18,7 @@ module Fairy
16
18
  @arrays = []
17
19
  @arrays_size = arrays_size
18
20
  @arrays_mutex = Mutex.new
19
- @arrays_cv = ConditionVariable.new
21
+ @arrays_cv = XThread::ConditionVariable.new
20
22
  end
21
23
 
22
24
  def size
@@ -5,6 +5,8 @@
5
5
 
6
6
  require "e2mmap"
7
7
 
8
+ require "xthread"
9
+
8
10
  require "fairy/share/conf.rb"
9
11
 
10
12
  module Fairy
@@ -48,7 +50,7 @@ module Fairy
48
50
 
49
51
  @real_file_names = []
50
52
  @real_file_names_mutex = Mutex.new
51
- @real_file_names_cv = ConditionVariable.new
53
+ @real_file_names_cv = XThread::ConditionVariable.new
52
54
 
53
55
  @base_name = nil
54
56
 
@@ -176,7 +178,7 @@ module Fairy
176
178
  @vfile_name = ary[0]
177
179
  @real_file_names = ary[1]
178
180
  @real_file_names_mutex = Mutex.new
179
- @real_file_names_cv = ConditionVariable.new
181
+ @real_file_names_cv = XThread::ConditionVariable.new
180
182
  end
181
183
 
182
184
  end