ossl-memory-usage-no-comp.rb

script to test memory usage - Eric Wong, 08/11/2011 05:52 AM

Download (1.06 KB)

 
1
require "openssl"
2
require "socket"
3
Thread.abort_on_exception = true
4
nr = 500
5

    
6
host = "127.0.0.1"
7
server = TCPServer.new(host, 0)
8
accepted = []
9
connected = []
10
port = server.addr[1]
11
server_ctx = OpenSSL::SSL::SSLContext.new
12
server_ctx.ciphers = "ALL"
13
client_ctx = OpenSSL::SSL::SSLContext.new
14
client_ctx.ciphers = "ALL"
15

    
16
server_ctx.options = client_ctx.options = case ENV["NOCOMP"].to_i
17
when 0
18
  puts "Compression enabled"
19
  OpenSSL::SSL::OP_ALL
20
else
21
  puts "Compression disabled"
22
  OpenSSL::SSL::OP_ALL | OpenSSL::SSL::OP_NO_COMPRESSION
23
end
24

    
25
server = OpenSSL::SSL::SSLServer.new(server, server_ctx)
26
server.start_immediately = true
27

    
28
wbuf = "HI"
29

    
30
thr = Thread.new do
31
  nr.times do
32
    client = server.accept
33
    client.write(wbuf)
34
    accepted << client
35
  end
36
end
37

    
38
nr.times do
39
  sock = TCPSocket.new(host, port)
40
  c = OpenSSL::SSL::SSLSocket.new(sock, client_ctx)
41
  c.connect
42
  c.read(2)
43
  connected << c
44
end
45
thr.join
46

    
47
begin
48
  puts File.readlines("/proc/#$$/status").grep(/VmRSS:/) # for Linux
49
rescue
50
  trap(:INT) { exit }
51
  puts "Check memory usage of pid=#$$, Ctrl-C when done"
52
  sleep
53
end