From 5f69a7f60467fa58c2f998daffab43e118bff36c Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Tue, 9 Feb 2021 19:39:56 +1300 Subject: Expose scheduler as public interface & bug fixes. (#3945) * Rename `rb_scheduler` to `rb_fiber_scheduler`. * Use public interface if available. * Use `rb_check_funcall` where possible. * Don't use `unblock` unless the fiber was non-blocking. --- test/fiber/http.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'test/fiber/http.rb') diff --git a/test/fiber/http.rb b/test/fiber/http.rb index ad51ae3c76..53a4602bd4 100644 --- a/test/fiber/http.rb +++ b/test/fiber/http.rb @@ -15,24 +15,25 @@ def fetch_topics(topics) topics.each do |topic| Fiber.new(blocking: Fiber.current.blocking?) do uri = URI("https://www.google.com/search?q=#{topic}") - responses[topic] = Net::HTTP.get(uri).scan(topic).size + response = Net::HTTP.get(uri) + responses[topic] = response.scan(topic).size end.resume end - Thread.fiber_scheduler&.run + Fiber.scheduler&.run return responses end def sweep(repeats: 3, **options) times = (1..8).map do |i| - $stderr.puts "Measuring #{i} topic(s)..." + $stderr.puts "Measuring #{i} topic(s) #{options.inspect}..." topics = TOPICS[0...i] Thread.new do Benchmark.realtime do scheduler = Scheduler.new - Fiber.set_scheduler scheduler + Fiber.set_scheduler(scheduler) repeats.times do Fiber.new(**options) do @@ -49,5 +50,5 @@ def sweep(repeats: 3, **options) puts JSON.dump(times.map{|value| value.round(3)}) end -sweep(blocking: true) +# sweep(blocking: true) sweep(blocking: false) -- cgit v1.2.3