Re: API Proposal for apr_thread_pool

2006-04-06 Thread Henry Jen

Henry Jen wrote:

William A. Rowe, Jr. wrote:

Henry Jen wrote:



/**
 * Stop all unused threads. Ignore the maximum number of idling threads.
 * @return The total number of threads stopped.
 */
APR_DECLARE(int) apr_thread_pool_stop_unused_threads(void);


I'm a little confused in your proposal between 
apr_thread_pool_terminate(),

apr_thread_pool_destroy(), and this function.

Can't this be reduced to



My mistake. The last couple functions should take a apr_thread_pool_t 
*self as a parameter. Those are instance methods, not static.




Another thing is that the initialize/terminate may not be needed. I put 
it there for now in case some thing I have overlooked.


Cheers,
Henry


Error 730038 - AcceptEx() problem?

2006-04-06 Thread Matti Eskelinen
Hello all,I'm new to this list, please forgive me for any ignorance I might manifest in my messages.But to get straight to the point, my task is to develop a small tcp server plugin with apr. I'm using a pollset to handle multiple requests and I put together a very simple test system following the instructions of the tutorial. The listening socket passes through the first request just fine, but when this request has been handled and in the pollset there is only the listening socket, the only thing I get from apr_pollset_poll is error 730038 (An operation was attempted on something that is not a socket). I managed to find out that with apache, this error has to do with AcceptEx() failing with winsock v2 on certain systems. Is there any other possible reason for this error that anybody is aware of?
This happens both when I create one request, handle it and then create another request and when I create two requests one after another. The first request gets handled, the second not; when there is only the listening socket in the pollset, I get only the error.
On apache, the use of AcceptEx can be disabled with directive Win32DisableAcceptEx. Now I'd like to know if there exists a way to achieve the same with apr. I'd like to test if disabling AcceptEx removes the error or should I look elsewhere. Is there already a compiler directive or something else to disable AcceptEx or should I dig into the apr code and implement such a directive myself? ;) If the latter is the case, could someone please point me to the right direction, since I'm completely new to apr and have only briefly looked at the code.
Thanks in advance for any help.-- Matti EskelinenSoftware Developer[EMAIL PROTECTED]


Re: API Proposal for apr_thread_pool

2006-04-06 Thread Henry Jen

William A. Rowe, Jr. wrote:

Henry Jen wrote:

Hi,

We would like to implement thread pool capability, and think it might 
be a good addition to apr-util or apr.


Interesting!

I don't see where your thread join occurs to reap any terminated threads,
that is, how your model handles threads that have decided they are 'done'.



The thread remains in the pool until the thread_pool tells the thread to 
stop and that's where join will happen.


One place is apr_thread_pool_stop_unused_threads.


APR_DECLARE(int) apr_thread_pool_get_num_unused_threads(void);


AIUI the style apr_thread_pool_unused_threads_num_get() would be 
appropriate

(_num seems awkward though, I personally prefer _count, or nothing).



I am OK with the naming convention as long as there is one. :-)


/**
 * Stop all unused threads. Ignore the maximum number of idling threads.
 * @return The total number of threads stopped.
 */
APR_DECLARE(int) apr_thread_pool_stop_unused_threads(void);


I'm a little confused in your proposal between apr_thread_pool_terminate(),
apr_thread_pool_destroy(), and this function.

Can't this be reduced to



My mistake. The last couple functions should take a apr_thread_pool_t 
*self as a parameter. Those are instance methods, not static.


This may address all the following questions.

Attached please find updated version.

Cheers,
Henry


  apr_thread_pool_shutdown()  (blocks)
  apr_thread_pool_destroy()   (same as pool cleanup)

Can you elaborate?

Final observation, your model seemed a little shortsighted, in that it 
permits
only a single thread pool.  This is great for an app, lousy for another 
library
which wishes to build upon the model.  And a group of threads might be 
shut down

independently of a second pool.

Can you refine the proposal with an apr_threadpool_t * object which 
prevents
us from adding yet another evil static singleton?  Or as an alternative, 
bind
the threadpool as an attribute of the pool itself, identifying the 
thread pool

by apr_pool_t *?

Bill



/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 * applicable.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifdef APR_THREAD_POOL_H
#define APR_THREAD_POOL_H

/**
 * @file apr_thread_pool.h
 * @brief APR Thread Pool Library

 * @remarks This library implements a thread pool using apr_thread_t. A thread
 * pool is a set of threads that can be created in advance or on demand until a
 * maximum number. When a task is scheduled, the thread pool will find an idle
 * thread to handle the task. In case all existing threads are busy, the pool
 * will try to create a new thread to serve the task if the maximum number has
 * not been reached. Otherwise, the task will be put into a queue based on
 * priority, which can be valued from 0 to 255, with higher value been served
 * first. In case there are tasks with the same priority, the new task is put at
 * the top or the bottom depeneds on which function is used to put the task.
 *
 * @remarks There may be the case that a thread pool can use up the maximum
 * number of threads at peak load, but having those threads idle afterwards. A
 * maximum number of idle threads can be set so that extra idling threads will
 * be terminated to save system resrouces. 
 */

#ifdef __cplusplus
extern C {
#if 0
};
#endif
#endif /* __cplusplus */

/** Opaque Thread Pool structure. */
typedef struct _apr_thread_pool apr_thread_pool_t;

/**
 * The prototype for any APR thread pool task functions.
 * @param apr_thread_t the apr_thread_t structure for the thread is executing the task
 * @param void * a pointer to the user data passed in when schedule the task
 */
typedef void* (APR_THREAD_FUNC *apr_thread_pool_task_t) (apr_thread_t *, void *)

#define APR_THREAD_TASK_PRIORITY_LOWEST 0
#define APR_THREAD_TASK_PRIORITY_LOW 63
#define APR_THREAD_TASK_PRIORITY_NORMAL 127
#define APR_THREAD_TASK_PRIORITY_HIGH 191
#define APR_THREAD_TASK_PRIORITY_HIGHEST 255

/**
 * Setup all of the internal structures required to use thread pools
 */
APR_DECLARE(apr_status_t) apr_thread_pool_init(void);

/**
 * Tear down all of the internal structures required to use pools
 */
APR_DECLARE(void) apr_thread_pool_terminate(void);

/**
 * Create a thread pool
 * @param pool The pool to use
 * @param init_threads The number of threads to be created initially, the number
 * will also be used as the initial value for maximum number of idle threads.
 * @param max_threads The maximum number of threads that can be 

Re: [PATCH] apr_thread_yield with pthread

2006-04-06 Thread Garrett Rooney
On 4/5/06, William A. Rowe, Jr. [EMAIL PROTECTED] wrote:
 This has been sitting out a while.  Any comments from the vocal majority
 on their favorite platform?  Seems sane to me, but needs eyes from folks
 intimately familiar with the pthreads implementation.

 I noticed more are trying to purge the bug queue so thought it's a good
 time to mention again.

I haven't actually tried it, but based on what I know of pthreads it
seems fine to me.

-garrett


Re: Error 730038 - AcceptEx() problem?

2006-04-06 Thread Garrett Rooney
On 4/5/06, Matti Eskelinen [EMAIL PROTECTED] wrote:
 Hello all,
 I'm new to this list, please forgive me for any ignorance I might manifest
 in my messages.

 But to get straight to the point, my task is to develop a small tcp server
 plugin with apr. I'm using a pollset to handle multiple requests and I put
 together a very simple test system following the instructions of the
 tutorial. The listening socket passes through the first request just fine,
 but when this request has been handled and in the pollset there is only the
 listening socket, the only thing I get from apr_pollset_poll is error 730038
 (An operation was attempted on something that is not a socket). I managed to
 find out that with apache, this error has to do with AcceptEx() failing with
 winsock v2 on certain systems. Is there any other possible reason for this
 error that anybody is aware of?

 This happens both when I create one request, handle it and then create
 another request and when I create two requests one after another. The first
 request gets handled, the second not; when there is only the listening
 socket in the pollset, I get only the error.

 On apache, the use of AcceptEx can be disabled with directive
 Win32DisableAcceptEx. Now I'd like to know if there exists a way to achieve
 the same with apr. I'd like to test if disabling AcceptEx removes the error
 or should I look elsewhere. Is there already a compiler directive or
 something else to disable AcceptEx or should I dig into the apr code and
 implement such a directive myself? ;) If the latter is the case, could
 someone please point me to the right direction, since I'm completely new to
 apr and have only briefly looked at the code.

As far as I know there is no way to make the pollset code not use
AcceptEx, so you'd have to implement such a thing yourself inside the
pollset code.

As for the potential bug, it would probably be easier for a
windows-savy developer to help you out if you actually posted the code
you're having trouble with.

-garrett


Re: Error 730038 - AcceptEx() problem?

2006-04-06 Thread Jeff Koftinoff
Garrett Rooney wrote:
 On 4/5/06, Matti Eskelinen [EMAIL PROTECTED] wrote:
   

 As far as I know there is no way to make the pollset code not use
 AcceptEx, so you'd have to implement such a thing yourself inside the
 pollset code.

 As for the potential bug, it would probably be easier for a
 windows-savy developer to help you out if you actually posted the code
 you're having trouble with.

 -garrett

   
The problem with AcceptEx is usually because of poorly written Windows
winsock 2 Layered Service Providers (LSP's)

I found this app which may help:

http://www.cexx.org/lspfix.htm

At one point in my life I had to write an LSP an haven't fully recovered
at just how backwards and difficult the WS2 architecture forced the
LSP's design to be.

Back then (on NT4 pre SP6), even a fully compliant LSP would cause
system boot failure because many required RPC based services would fail
because of the ability of LSP's to make file handles that are unusable
with select() and friends. At that time, I believe you were not allowed
to call select on a bunch of handles if those handles were
created/managed by different LSP's. I don't know if that has changed
since then.


More information about the absurd brain dead design (IMHO) of LSP's are at:
http://www.microsoft.com/msj/0599/LayeredService/LayeredService.aspx

Microsoft has a nifty tool which will show you all the LSP's in your
system, and give you the option of re-ordering them.

If AcceptEx() fails on numerous LSP's, then there should be an option in
apr to work around it.

Of course the best solution would be to get LSP's that are fixed but
that is problematic. LSP's are used for encrypted tunnels and content
filtering, etc.

Regards,
Jeff


Re: DBD: Prepared statements with PGSQL

2006-04-06 Thread Bojan Smojver

Quoting Bojan Smojver [EMAIL PROTECTED]:


Is there are particular reason why PQprepare() isn't used to prepare
statements? Currently, DBD code builds an SQL statement with PREPARE
[...] at the beginning and then executes that, instead of calling the
mentioned API function.


Don't worry about answering this. Looks like 7.4 doesn't have this  
call, so I'm guessing it a backward compatibility thing.


--
Bojan