File: client.rb

package info (click to toggle)
ruby-async-io 1.34.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 424 kB
  • sloc: ruby: 3,103; makefile: 4
file content (44 lines) | stat: -rwxr-xr-x 950 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH << File.expand_path("../../lib", __dir__)

require 'async/reactor'
require 'async/io/host_endpoint'

require 'async/container'
require 'async/container/forked'

endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7234")

CONNECTIONS = 1_000_000

CONCURRENCY = Async::Container.processor_count
TASKS = 16
REPEATS = (CONNECTIONS.to_f / (TASKS * CONCURRENCY)).ceil

puts "Starting #{CONCURRENCY} processes, running #{TASKS} tasks, making #{REPEATS} connections."
puts "Total number of connections: #{CONCURRENCY * TASKS * REPEATS}!"

begin
	container = Async::Container::Forked.new
	
	container.run(count: CONCURRENCY) do
		Async do |task|
			connections = []
			
			TASKS.times do
				task.async do
					REPEATS.times do
						$stdout.write "."
						connections << endpoint.connect
					end
				end
			end
		end
	end
	
	container.wait
ensure
	container.stop if container
end