Re: [HACKERS] Dynamic Background Workers and clean exit

2014-04-16 Thread Robert Haas
On Wed, Apr 16, 2014 at 5:27 AM, Petr Jelinek wrote: > Hello, > > I've been recently doing some work with dynamic bgworkers and noticed that I > have no way of saying "I am done now and want to exit cleanly" because > bgworkers get restarted automatically on exit code 0 no matter what is the > res

[HACKERS] Dynamic Background Workers and clean exit

2014-04-16 Thread Petr Jelinek
Hello, I've been recently doing some work with dynamic bgworkers and noticed that I have no way of saying "I am done now and want to exit cleanly" because bgworkers get restarted automatically on exit code 0 no matter what is the restart interval set to. I understand the rationale for this b

Re: [HACKERS] Dynamic background workers & docs question

2014-03-24 Thread Michael Paquier
On Mon, Mar 24, 2014 at 11:03 PM, Magnus Hagander wrote: > That's what I thought. Can a dynamic background worker start *another* > dynamic background worker, or can they only be started from "first level" > background workers? I have never really tried by myself, but I don't see any reason why it

Re: [HACKERS] Dynamic background workers & docs question

2014-03-24 Thread Magnus Hagander
On Mon, Mar 24, 2014 at 12:20 PM, Michael Paquier wrote: > On Mon, Mar 24, 2014 at 5:54 PM, Magnus Hagander > wrote: > > I was looking at > http://www.postgresql.org/docs/devel/static/bgworker.html > > with a client today. > > > > It says: > > "Unlike RegisterBackgroundWorker, which can only be

Re: [HACKERS] Dynamic background workers & docs question

2014-03-24 Thread Michael Paquier
On Mon, Mar 24, 2014 at 5:54 PM, Magnus Hagander wrote: > I was looking at http://www.postgresql.org/docs/devel/static/bgworker.html > with a client today. > > It says: > "Unlike RegisterBackgroundWorker, which can only be called from within the > postmaster,RegisterDynamicBackgroundWorker must be

[HACKERS] Dynamic background workers & docs question

2014-03-24 Thread Magnus Hagander
I was looking at http://www.postgresql.org/docs/devel/static/bgworker.htmlwith a client today. It says: "Unlike RegisterBackgroundWorker, which can only be called from within the postmaster,RegisterDynamicBackgroundWorker must be called from a regular backend." Is that the correct restriction? In

Re: [HACKERS] dynamic background workers, round two

2013-08-28 Thread Andres Freund
On 2013-08-28 14:04:59 -0400, Robert Haas wrote: > >> + RegisterDynamicBackgroundWorker(BackgroundWorker > >> + *worker, BackgroundWorkerHandle **handle). Unlike > >> + RegisterBackgroundWorker, which can only be called from > >> within > >> + the postmaster, RegisterDynamicBackgroundWorker

Re: [HACKERS] dynamic background workers, round two

2013-08-28 Thread Robert Haas
On Wed, Aug 28, 2013 at 2:04 PM, Robert Haas wrote: >> Hm. Not this patches fault, but We seem to allow bgw_start_time == >> BgWorkerStart_PostmasterStart here which doesn't make sense... > > I can add a check for that. I agree that it's a separate patch. On third thought, is there really any po

Re: [HACKERS] dynamic background workers, round two

2013-08-28 Thread Robert Haas
On Wed, Aug 28, 2013 at 2:04 PM, Robert Haas wrote: > I certainly can't promise that the code is bug-free. But I think it's > probably better to get this into the tree and let people start playing > around with it than to continue to maintain it in my private sandbox. > At this point it's just in

Re: [HACKERS] dynamic background workers, round two

2013-08-28 Thread Robert Haas
On Tue, Aug 27, 2013 at 9:50 AM, Andres Freund wrote: >> > BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, >> > pid_t *pid); >> > BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle >> > *handle, pid_t *pid); >> >> OK, here's a patch that API. I renamed

Re: [HACKERS] dynamic background workers, round two

2013-08-27 Thread Andres Freund
On 2013-07-26 08:50:51 -0400, Robert Haas wrote: > > > > Btw, you seem to want to support this in bgworkers started by a > > > > bgworker. That's not going to work without some changes if the > > > > "intermediate" bgworker is one without a backend since those don't use > > > > procsignal_sigusr1_h

Re: [HACKERS] dynamic background workers, round two

2013-08-27 Thread Andres Freund
Hi Robert, On 2013-08-17 12:08:17 -0400, Robert Haas wrote: > On Sun, Aug 11, 2013 at 1:31 AM, Andres Freund wrote: > > So, I'd suggest something like: > > > > typedef enum BgwHandleStatus { > >BGWH_SUCCESS, /* sucessfully got status */ > >BGWH_NOT_YET, /* worker hasn't started yet */ > >

Re: [HACKERS] dynamic background workers, round two

2013-08-17 Thread Robert Haas
On Sun, Aug 11, 2013 at 1:31 AM, Andres Freund wrote: > So, I'd suggest something like: > > typedef enum BgwHandleStatus { >BGWH_SUCCESS, /* sucessfully got status */ >BGWH_NOT_YET, /* worker hasn't started yet */ >BGWH_GONE, /* worker had been started, but shut down already */ >BG

Re: [HACKERS] dynamic background workers, round two

2013-08-10 Thread Andres Freund
[sent again, previously sent as reply, instead of reply-all, thanks Robert] On 2013-08-09 09:09:08 -0400, Robert Haas wrote: > On Fri, Jul 26, 2013 at 8:50 AM, Robert Haas wrote: > > On Fri, Jul 26, 2013 at 5:34 AM, Andres Freund > > wrote: > >> It doesn't need to be the postmaster, but I think

Re: [HACKERS] dynamic background workers, round two

2013-07-26 Thread Robert Haas
On Fri, Jul 26, 2013 at 5:34 AM, Andres Freund wrote: > It doesn't need to be the postmaster, but I think we need to provide > central infrastructure for that. I don't want this to end up being > redone poorly in multiple places. > I just wanted to mention it, it obviously doesn't need to be imple

Re: [HACKERS] dynamic background workers, round two

2013-07-26 Thread Andres Freund
On 2013-07-25 12:35:30 -0400, Robert Haas wrote: > On Wed, Jul 24, 2013 at 5:34 PM, Andres Freund wrote: > > This seems like a sensible idea to me. But, in the context of dynamic > > query, don't we also need the reverse infrastructure of notifying a > > bgworker that the client, that requested it

Re: [HACKERS] dynamic background workers, round two

2013-07-25 Thread Robert Haas
On Wed, Jul 24, 2013 at 5:34 PM, Andres Freund wrote: > This seems like a sensible idea to me. But, in the context of dynamic > query, don't we also need the reverse infrastructure of notifying a > bgworker that the client, that requested it to be started, has died? > Ending up with a dozen bgwork

Re: [HACKERS] dynamic background workers, round two

2013-07-24 Thread Michael Paquier
On Thu, Jul 25, 2013 at 8:05 AM, Andres Freund wrote: > On 2013-07-25 08:03:17 +0900, Michael Paquier wrote: > > On Thu, Jul 25, 2013 at 6:34 AM, Andres Freund >wrote: > > > > > > --- a/contrib/worker_spi/worker_spi.c > > > > +++ b/contrib/worker_spi/worker_spi.c > > > > > > Btw, I've posted a mi

Re: [HACKERS] dynamic background workers, round two

2013-07-24 Thread Andres Freund
On 2013-07-25 08:03:17 +0900, Michael Paquier wrote: > On Thu, Jul 25, 2013 at 6:34 AM, Andres Freund wrote: > > > > --- a/contrib/worker_spi/worker_spi.c > > > +++ b/contrib/worker_spi/worker_spi.c > > > > Btw, I've posted a minimal regression test for bworkers/worker_spi in > > 20130724175742.gd

Re: [HACKERS] dynamic background workers, round two

2013-07-24 Thread Michael Paquier
On Thu, Jul 25, 2013 at 6:34 AM, Andres Freund wrote: > > --- a/contrib/worker_spi/worker_spi.c > > +++ b/contrib/worker_spi/worker_spi.c > > Btw, I've posted a minimal regression test for bworkers/worker_spi in > 20130724175742.gd10...@alap2.anarazel.de - I'd like to see some coverage > of this..

Re: [HACKERS] dynamic background workers, round two

2013-07-24 Thread Michael Paquier
On Thu, Jul 25, 2013 at 6:34 AM, Andres Freund wrote: > Hi, > > On 2013-07-24 12:46:21 -0400, Robert Haas wrote: > > The attached patch attempts to remedy this problem. When you register > > a background worker, you can obtain a "handle" that can subsequently > > be used to query for the worker's

Re: [HACKERS] dynamic background workers, round two

2013-07-24 Thread Andres Freund
Hi, On 2013-07-24 12:46:21 -0400, Robert Haas wrote: > The attached patch attempts to remedy this problem. When you register > a background worker, you can obtain a "handle" that can subsequently > be used to query for the worker's PID. If you additionally initialize > bgw_notify_pid = MyProcPid

[HACKERS] dynamic background workers, round two

2013-07-24 Thread Robert Haas
The dynamic background workers patch that I submitted for CF1 was generally well-received, but several people commented on a significant limitation: there's currently no way for a backend that requests a new background worker to know whether that background worker was successfully started. If you'

Re: [HACKERS] dynamic background workers

2013-07-16 Thread Robert Haas
On Wed, Jul 3, 2013 at 11:15 AM, Alvaro Herrera wrote: > Andres Freund escribió: >> Just as a datapoint, if you benchmark the numbers of forks that can be >> performed by a single process (i.e. postmaster) the number is easily in >> the 10s of thousands. Now forking that much has some scalability

Re: [HACKERS] dynamic background workers

2013-07-03 Thread Michael Paquier
On Wed, Jul 3, 2013 at 11:19 PM, Robert Haas wrote: > On Mon, Jun 24, 2013 at 3:51 AM, Michael Paquier > wrote: >> 3) Why not adding an other function in worker_spi.c being the opposite >> of worker_spi_launch to stop dynamic bgworkers for a given index >> number? This would be only a wrapper of

Re: [HACKERS] dynamic background workers

2013-07-03 Thread Alvaro Herrera
Andres Freund escribió: > Just as a datapoint, if you benchmark the numbers of forks that can be > performed by a single process (i.e. postmaster) the number is easily in > the 10s of thousands. Now forking that much has some scalability > implications inside the kernel, but still. > I'd be surpri

Re: [HACKERS] dynamic background workers

2013-07-03 Thread Robert Haas
On Mon, Jun 24, 2013 at 3:51 AM, Michael Paquier wrote: > 3) Why not adding an other function in worker_spi.c being the opposite > of worker_spi_launch to stop dynamic bgworkers for a given index > number? This would be only a wrapper of pg_terminate_backend, OK, but > at least it would give the u

Re: [HACKERS] dynamic background workers

2013-06-24 Thread Michael Paquier
Hi, Please find some review for the 2nd patch, with the 1st patch applied on top of it. On Sat, Jun 15, 2013 at 6:00 AM, Robert Haas wrote: > The second patch, dynamic-bgworkers-v1.patch, revises the background > worker API to allow background workers to be started dynamically. > This requires s

Re: [HACKERS] dynamic background workers

2013-06-20 Thread Andres Freund
On 2013-06-20 11:29:27 -0400, Robert Haas wrote: > > Do you mean pre-forking and connecting to a specific database? Or really > > just the forking? > > I've considered both at various times, although in this context I was > mostly thinking about just the forking. Pre-connecting to a specific > dat

Re: [HACKERS] dynamic background workers

2013-06-20 Thread Robert Haas
On Thu, Jun 20, 2013 at 10:59 AM, Markus Wanner wrote: > On 06/20/2013 04:41 PM, Robert Haas wrote: >> The constant factor is also very small. Generally, I would expect >> num_worker_processes <~ # CPUs > > That assumption might hold for parallel querying, yes. In case of > Postgres-R, it doesn't

Re: [HACKERS] dynamic background workers

2013-06-20 Thread Markus Wanner
On 06/20/2013 04:41 PM, Robert Haas wrote: > The constant factor is also very small. Generally, I would expect > num_worker_processes <~ # CPUs That assumption might hold for parallel querying, yes. In case of Postgres-R, it doesn't. In the worst case, i.e. with a 100% write load, a cluster of n

Re: [HACKERS] dynamic background workers

2013-06-20 Thread Robert Haas
On Thu, Jun 20, 2013 at 9:57 AM, Markus Wanner wrote: > That sounds like a good simplification. Even if it's an O(n) operation, > the n in question here has relatively low practical limits. It's > unlikely to be much of a concern, I guess. The constant factor is also very small. Generally, I wou

Re: [HACKERS] dynamic background workers

2013-06-20 Thread Markus Wanner
Robert, On 06/14/2013 11:00 PM, Robert Haas wrote: > Parallel query, or any subset of that project such as parallel sort, > will require a way to start background workers on demand. thanks for continuing this, very much appreciated. Postgres-R and thus TransLattice successfully use a similar appr

Re: [HACKERS] dynamic background workers

2013-06-20 Thread Robert Haas
On Mon, Jun 17, 2013 at 10:45 PM, Peter Eisentraut wrote: > On Fri, 2013-06-14 at 17:00 -0400, Robert Haas wrote: >> Alvaro's work on 9.3, we now have the ability to configure background >> workers via shared_preload_libraries. But if you don't have the right >> library loaded at startup time, an

Re: [HACKERS] dynamic background workers

2013-06-18 Thread Michael Paquier
Hi, On Sat, Jun 15, 2013 at 6:00 AM, Robert Haas wrote: > The first patch, max-worker-processes-v1.patch, adds a new GUC > max_worker_processes, which defaults to 8. This fixes the problem > discussed here: > > http://www.postgresql.org/message-id/CA+TgmobguVO+qHnHvxBA2TFkDhw67Y=4bp405fvabec_eto

Re: [HACKERS] dynamic background workers

2013-06-17 Thread Peter Eisentraut
On Fri, 2013-06-14 at 17:00 -0400, Robert Haas wrote: > Alvaro's work on 9.3, we now have the ability to configure background > workers via shared_preload_libraries. But if you don't have the right > library loaded at startup time, and subsequently wish to add a > background worker while the serve

Re: [HACKERS] dynamic background workers

2013-06-17 Thread Christopher Browne
BTW, one of the ideas that popped up in the unConference session on replication was "why couldn't we use a background worker as a replication agent?" The main reason pointed out was 'because that means you have to restart the postmaster to add a replication agent.' (e.g. - like a Slony "slon" pro

Re: [HACKERS] dynamic background workers

2013-06-16 Thread Simon Riggs
On 14 June 2013 22:00, Robert Haas wrote: > Parallel query, or any subset of that project such as parallel sort, > will require a way to start background workers on demand. Thanks to > Alvaro's work on 9.3, we now have the ability to configure background > workers via shared_preload_libraries. B

Re: [HACKERS] dynamic background workers

2013-06-14 Thread Michael Paquier
On Sat, Jun 15, 2013 at 6:00 AM, Robert Haas wrote: > The second patch, dynamic-bgworkers-v1.patch, revises the background > worker API to allow background workers to be started dynamically. > This requires some communication channel from ordinary workers to the > postmaster, because it is the po