From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS6939 64.71.128.0/18 X-Spam-Status: No, score=-1.4 required=3.0 tests=AWL,BAYES_00,FREEMAIL_FROM, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=ham version=3.3.2 Path: news.gmane.org!not-for-mail From: "=?utf-8?b?0K7RgNC40Lkg0KHQvtC60L7Qu9C+0LI=?=" Newsgroups: gmane.comp.lang.ruby.kgio.general Subject: Re: [PATCH 3/3] add `#kgio_writev` and `#kgio_trywritev` Date: Thu, 31 May 2012 10:26:53 +0400 Message-ID: References: <1338386216-14568-1-git-send-email-funny.falcon@gmail.com> <1338386216-14568-3-git-send-email-funny.falcon@gmail.com> <20120530203915.GB17661@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: dough.gmane.org 1338445642 3767 80.91.229.3 (31 May 2012 06:27:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 31 May 2012 06:27:22 +0000 (UTC) To: kgio@librelist.com Original-X-From: kgio@librelist.com Thu May 31 08:27:21 2012 Return-path: Envelope-to: gclrkg-kgio@m.gmane.org List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: kgio@librelist.com Xref: news.gmane.org gmane.comp.lang.ruby.kgio.general:165 Archived-At: Received: from zedshaw.xen.prgmr.com ([64.71.167.205]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SZyqs-0006cd-8Z for gclrkg-kgio@m.gmane.org; Thu, 31 May 2012 08:27:18 +0200 Received: from zedshaw.xen.prgmr.com (localhost [IPv6:::1]) by zedshaw.xen.prgmr.com (Postfix) with ESMTP id B5E2921DD05 for ; Thu, 31 May 2012 06:35:10 +0000 (UTC) Content-Transfer-Encoding: 7bit X-Content-Filtered-By: PublicInbox::Filter 0.0.1 2012/5/31 Eric Wong > Sokolov Yura 'funny-falcon wrote: > > > +#define WRITEV_MEMLIMIT (2*1024*1024) > > I'm not sure if the mem limit is a good idea. writev is meant to be > atomic (at least to regular files), and the strings are in memory, > anyways, I don't think having an extra copy will users hurt badly. > Don't need to worry about mmap()'ed regions in Ruby, either. > Well, kgio is more about dealing with sockets, and in reality socket rarely has buffer more than 512KB (I think, 1MB is a real practical limit) > > + > > + if (iov_cnt > 1) { > > + cur = buf = (char*)malloc(total); > > + if (!buf) rb_memerror(); > > All Rubies with C API provide xmalloc(), use that instead, especially > since you're already using rb_memerror(). > Rubies xmalloc could trigger Garbage Collection (and it is very likely in our case). I don't think GC is good idea cause we will free our allocation literally "in next processor tick" > > I suggest preserving errno from write(), free() can call brk/sbrk/munmap > that fail and set errno. > > if (iov_cnt > 1) { > int save_errno = errno; > free(buf); > errno = save_errno; > } > > Big thanks for pointing to :) > > + def test_monster_writev_wait_writable > > + @wr.instance_variable_set :@nr, 0 > > + def @wr.kgio_wait_writable > > + @nr += 1 > > + IO.select(nil, [self]) > > + end > > + buf = ["." * 1024] * 1024 * 10 > > + buf_size = buf.inject(0){|c, s| c + s.size} > > + thr = Thread.new { @wr.kgio_writev(buf) } > > I had trouble with this test on the last assertion. > > Adding this here helped: > > Thread.pass until thr.stop? > > (Using a dual core machine with plenty of memory for skbs). > I have same problem with `test_moster_write_wait_writable` when testing on Unix sockets. It seems that Unix sockets are very - very fast. So that, I think this addition should be in both test methods. > > > + readed = @rd.read(buf_size) > > + thr.join > > + assert_nil thr.value > > + assert_equal buf.join, readed > > + assert @wr.instance_variable_get(:@nr) > 0 > > + end > Thank you for other minor issues, I'll try to consider them. With regards, Sokolov Yura aka funny_falcon