Re: Inefficient bytea escaping?

From: "Marko Kreen" <markokr(at)gmail(dot)com>
To: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Andreas Pflug" <pgadmin(at)pse-consulting(dot)de>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Inefficient bytea escaping?
Date: 2006-05-27 17:23:35
Message-ID: e51f66da0605271023h2b45ea00l37c5cf467da930ac@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 5/27/06, Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:
> Given there is no way to know if you're running single threaded or not,
> I don't think glibc can take chances like that.

There's CPP symbol _REENTRANT for that and in run time,
libc can detect call to pthread_create [1].

> In any case, this isn't the issue here. Glibc doesn't do any locking
> unless pthread is linked in. Ofcourse, it takes a few cycles to
> determine that, but I don't think that'd cause a major slowdown.

You are conflicting with your previous paragraph :)

Otherwise you are right - that how a libc obviously should work, right?

http://marc.theaimsgroup.com/?l=glibc-alpha&m=100775741325472&w=2
http://marc.theaimsgroup.com/?l=glibc-alpha&m=112110641923178&w=2

I did a small test that does several fputc calls to /dev/null,
with various workarounds:

* lock.enabled is standard app.
* lock.disabled calls __fsetlocking(FSETLOCKING_BYCALLER),
as suggested by Ulrich Drepper.
* lock.unlocked calls fputc_unlocked

lock.enabled 48s
lock.disabled 28s
lock.unlocked 25s

I attached the test, you can measure yourself.

So I prepared a patch that calls __fsetlocking() in AllocateFile.
Andreas, Tom could you measure if it makes any difference?

--
marko

[1] In the first thread I linked, there was very clever
optimisation proposed using this function, that would
quarantee thread-safety even without _REENTRANT.

Unfortunately, event if U. Drepper changes his mind someday
and fixes the locking for singe-threaded apps, it would
very likely break binary compatibility with old apps,
so it wont happen in the near future.

Attachment Content-Type Size
test-locking.tgz application/x-gzip 558 bytes
disable-glibc-locking.diff text/plain 856 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gurjeet Singh 2006-05-27 17:57:11 error in compilation!
Previous Message Martijn van Oosterhout 2006-05-27 16:27:48 Re: Inefficient bytea escaping?