Project

General

Profile

Actions

Feature #11298

closed

[PATCH] socket: memoize common socket families in fptr->mode

Added by normalperson (Eric Wong) almost 9 years ago. Updated over 8 years ago.

Status:
Closed
Target version:
-
[ruby-core:69713]

Description

I noticed an unnecesary getsockname() syscalls for every
sendmsg_nonblock call I make on SOCK_SEQPACKET pair.
This made for a noisy strace.

I also plan on following up and setting the flag on
rsock_init_* functions upon initialization.

And probably caching Addrinfo somehow on accepted sockets.

I'll commit this in a week or two if no comments.

  require 'socket'
  require 'benchmark'
  nr = 100000
  msg = 'hello world'
  buf = ''
  size = msg.bytesize
  puts(Benchmark.measure do
    UNIXSocket.pair(:SEQPACKET) do |a, b|
      nr.times do
        a.sendmsg_nonblock(msg, 0, exception: false)
        b.recv(size, 0, buf)
      end
    end
  end)

             user     system      total        real
before:  0.290000   0.240000   0.530000 (  0.534527)
 after:  0.330000   0.340000   0.670000 (  0.678235)

Files

Updated by funny_falcon (Yura Sokolov) almost 9 years ago

Did you make a mistake, or after is really slower?

Updated by normalperson (Eric Wong) almost 9 years ago

wrote:

Did you make a mistake, or after is really slower?

Good catch! I mislabeled the lines. This patch makes things faster.

Actions #3

Updated by Anonymous over 8 years ago

  • Status changed from Open to Closed

Applied in changeset r51097.


socket: memoize common socket families in fptr->mode

This provides a minor speedup by avoiding an extra syscall

require 'socket'
require 'benchmark'
nr = 100000
msg = 'hello world'
buf = ''
size = msg.bytesize
puts(Benchmark.measure do
  UNIXSocket.pair(:SEQPACKET) do |a, b|
    nr.times do
      a.sendmsg_nonblock(msg, 0, exception: false)
      b.recv(size, 0, buf)
    end
  end
end)

         user     system      total        real

before: 0.330000 0.340000 0.670000 ( 0.678235)
after: 0.290000 0.240000 0.530000 ( 0.534527)

  • ext/socket/rubysocket.h: flags for common socket families
    (rsock_getfamily): update signature
  • include/ruby/io.h: comment socket FMODE flags
  • ext/socket/init.c (rsock_getfamily): memoize family
  • ext/socket/basicsocket.c: adjust rsock_getfamily calls
  • ext/socket/ancdata.c: ditto
    [ruby-core:69713] [Feature #11298]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0