agora inbox for pljava-dev@postgresql.org  
help / color / mirror / Atom feed
[Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
13+ messages / 0 participants
[nested] [flat]

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-03-08 10:21  
  0 siblings, 2 replies; 13+ messages in thread

From:  @ 2014-03-08 10:21 UTC (permalink / raw)

Hello,

Is PL/Java safe to use in terms of its threading design?  I've just asked 
pgsql-hackers about this and am waiting for response, adding the sentence:

"To put the question in other words, is it safe to load a multi-threaded PL 
library in the single-threaded backend process, if the PL only calls SPI in 
the main thread?"

My understanding is:

* PL/Java (pljava.so) is linked with the JNI (Java Native Interface) 
library, libjvm.so, in JRE.  libjvm.so is linked with libpthread.so, because 
Java VM is multi-threaded.  SO, "ldd pljava.so" shows libjvm.so and 
libpthread.so. pljava.so doesn't seem to be built for multh-threading ---  
none of -mt, -D_REENTRANT or -D_POSIX_C_SOURCE is specified when building 
it.

* When the application calls Java stored function, pljava.so calls a 
function in libjvm.so to create a JVM in the backend process, then invokes 
the user-defined Java method in the main thread.  The user-defined Java 
method calls JDBC methods to access database.  The JDBC method calls are 
translated to backend SPI function calls through JNI.

* The main thread can create Java threads using Java Thread API, and those 
threads can call JDBC methods.  However, PL/Java intercepts JDBC method 
calls and serializes SPI calls.  So, only one thread calls SPI functions at 
a time.  I'm wondering if this is the reason why PL/Java is safe for use.


What I'm concerned about is whether multi-threaded code (Java VM) can run 
safely in a single-threaded code (postgres).  I cannot point out what can be 
a particular problem with PL/Java, but in general, the mixture of 
single-threaded code and multi-threaded one seems to cause trouble around 
handling errno, memory and file handles/pointers.

FYI, JNI specification says that the code called from Java VM should be 
built for multi-threading as follows.  But postgres is not.

http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html#wp9502

[Excerpt]
Compiling, Loading and Linking Native Methods
Since the Java VM is multithreaded, native libraries should also be compiled 
and linked with multithread aware native compilers. For example, the -mt 
flag should be used for C++ code compiled with the Sun Studio compiler. For 
code complied with the GNU gcc compiler, the flags -D_REENTRANT 
or -D_POSIX_C_SOURCE should be used. For more information please refer to 
the native compiler documentation.

Regards
MauMau




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-03-09 11:06  
  parent: 
  1 sibling, 0 replies; 13+ messages in thread

From:  @ 2014-03-09 11:06 UTC (permalink / raw)

On 2014-03-08 11:21, MauMau wrote:
> Hello,
>
> Is PL/Java safe to use in terms of its threading design?  I've just 
> asked pgsql-hackers about this and am waiting for response, adding the 
> sentence:
>
> "To put the question in other words, is it safe to load a 
> multi-threaded PL library in the single-threaded backend process, if 
> the PL only calls SPI in the main thread?"
>
> My understanding is:
>
> * PL/Java (pljava.so) is linked with the JNI (Java Native Interface) 
> library, libjvm.so, in JRE.  libjvm.so is linked with libpthread.so, 
> because Java VM is multi-threaded.  SO, "ldd pljava.so" shows 
> libjvm.so and libpthread.so. pljava.so doesn't seem to be built for 
> multh-threading ---  none of -mt, -D_REENTRANT or -D_POSIX_C_SOURCE is 
> specified when building it.
That wouldn't do much good since the psql backend that it links with 
isn't built for multi-threading. This is also why the PL/Java protects 
all calls to the psql backend. Only one single thread at a time can call 
back to the backend.

>
> * When the application calls Java stored function, pljava.so calls a 
> function in libjvm.so to create a JVM in the backend process, then 
> invokes the user-defined Java method in the main thread.  The 
> user-defined Java method calls JDBC methods to access database. The 
> JDBC method calls are translated to backend SPI function calls through 
> JNI.
>
That sounds correct.

> * The main thread can create Java threads using Java Thread API, and 
> those threads can call JDBC methods.  However, PL/Java intercepts JDBC 
> method calls and serializes SPI calls. So, only one thread calls SPI 
> functions at a time.  I'm wondering if this is the reason why PL/Java 
> is safe for use.
>
Yes.

>
> What I'm concerned about is whether multi-threaded code (Java VM) can 
> run safely in a single-threaded code (postgres).  I cannot point out 
> what can be a particular problem with PL/Java, but in general, the 
> mixture of single-threaded code and multi-threaded one seems to cause 
> trouble around handling errno, memory and file handles/pointers.
>
While I understand your concern, I still believe that the PL/Java code 
base does what's needed to run together with the PostgreSQL 
single-threaded back-end. I don't think there are any problems with 
errno or pointers. If there was, such problems would become apparent 
immediately. Either as linker problems or as a general crash when the 
runtime boots up. No such problems have been reported AFAIK.

> FYI, JNI specification says that the code called from Java VM should 
> be built for multi-threading as follows.  But postgres is not.
>
> http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html#wp9502 
>
>
> [Excerpt]
> Compiling, Loading and Linking Native Methods
> Since the Java VM is multithreaded, native libraries should also be 
> compiled and linked with multithread aware native compilers. For 
> example, the -mt flag should be used for C++ code compiled with the 
> Sun Studio compiler. For code complied with the GNU gcc compiler, the 
> flags -D_REENTRANT or -D_POSIX_C_SOURCE should be used. For more 
> information please refer to the native compiler documentation.
>
All true, but here we're marrying a JVM runtime with a single threaded 
PostgreSQL backend. Normal recommendations don't really apply.

If you have time to really stress test PL/Java with respect to compiler 
flags etc. that would of course be very valuable. I haven't performed 
such tests since I first built PL/Java back in 2004. A lot has happened 
since.

- thomas

> Regards
> MauMau
>
> _______________________________________________
> Pljava-dev mailing list
> Pljava-dev at lists.pgfoundry.org
> http://lists.pgfoundry.org/mailman/listinfo/pljava-dev




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-03-16 01:56  
  parent: 
  1 sibling, 2 replies; 13+ messages in thread

From:  @ 2014-03-16 01:56 UTC (permalink / raw)

I got the reply in pgsql-hackers about this.  According to Tom's comment, 
I'm worried about PL/Java's design.

http://www.postgresql.org/message-id/11347.1394545919 at sss.pgh.pa.us

Is there any rationale that it's safe for PL/Java to:

* load multi-threaded Java VM in single-threaded postgres process (which is 
what Tom is concerned about)

* make multi-threaded Java VM load single-threaded pljava.so (which is what 
JNI specification says should not be done).


----- Original Message ----- 
From: "MauMau" <maumau307 at gmail.com>
To: <pljava-dev at lists.pgfoundry.org>
Sent: Saturday, March 08, 2014 7:21 PM
Subject: Is it safe to use multi-threaded PL/Java in single-threaded 
postgres process?


> Hello,
>
> Is PL/Java safe to use in terms of its threading design?  I've just asked 
> pgsql-hackers about this and am waiting for response, adding the sentence:
>
> "To put the question in other words, is it safe to load a multi-threaded 
> PL library in the single-threaded backend process, if the PL only calls 
> SPI in the main thread?"
>
> My understanding is:
>
> * PL/Java (pljava.so) is linked with the JNI (Java Native Interface) 
> library, libjvm.so, in JRE.  libjvm.so is linked with libpthread.so, 
> because Java VM is multi-threaded.  SO, "ldd pljava.so" shows libjvm.so 
> and libpthread.so. pljava.so doesn't seem to be built for 
> multh-threading ---  none of -mt, -D_REENTRANT or -D_POSIX_C_SOURCE is 
> specified when building it.
>
> * When the application calls Java stored function, pljava.so calls a 
> function in libjvm.so to create a JVM in the backend process, then invokes 
> the user-defined Java method in the main thread.  The user-defined Java 
> method calls JDBC methods to access database.  The JDBC method calls are 
> translated to backend SPI function calls through JNI.
>
> * The main thread can create Java threads using Java Thread API, and those 
> threads can call JDBC methods.  However, PL/Java intercepts JDBC method 
> calls and serializes SPI calls.  So, only one thread calls SPI functions 
> at a time.  I'm wondering if this is the reason why PL/Java is safe for 
> use.
>
>
> What I'm concerned about is whether multi-threaded code (Java VM) can run 
> safely in a single-threaded code (postgres).  I cannot point out what can 
> be a particular problem with PL/Java, but in general, the mixture of 
> single-threaded code and multi-threaded one seems to cause trouble around 
> handling errno, memory and file handles/pointers.
>
> FYI, JNI specification says that the code called from Java VM should be 
> built for multi-threading as follows.  But postgres is not.
>
> http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html#wp9502
>
> [Excerpt]
> Compiling, Loading and Linking Native Methods
> Since the Java VM is multithreaded, native libraries should also be 
> compiled and linked with multithread aware native compilers. For example, 
> the -mt flag should be used for C++ code compiled with the Sun Studio 
> compiler. For code complied with the GNU gcc compiler, the 
> flags -D_REENTRANT or -D_POSIX_C_SOURCE should be used. For more 
> information please refer to the native compiler documentation.




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-03-16 02:04  
  parent: 
  1 sibling, 1 reply; 13+ messages in thread

From:  @ 2014-03-16 02:04 UTC (permalink / raw)

So, I really think this question has been definitively answered. If you can produce a test case of your concerns which demonstrates the issue, we can discuss it. But the simple answer to your question is simply: yes. Pl/java obeys the rules and works according to spec. It does the right thing in the right way using the best practices. 

> On Mar 15, 2014, at 8:56 PM, MauMau <maumau307 at gmail.com> wrote:
> 
> I got the reply in pgsql-hackers about this.  According to Tom's comment, I'm worried about PL/Java's design.
> 
> http://www.postgresql.org/message-id/11347.1394545919 at sss.pgh.pa.us
> 
> Is there any rationale that it's safe for PL/Java to:
> 
> * load multi-threaded Java VM in single-threaded postgres process (which is what Tom is concerned about)
> 
> * make multi-threaded Java VM load single-threaded pljava.so (which is what JNI specification says should not be done).
> 
> 
> ----- Original Message ----- From: "MauMau" <maumau307 at gmail.com>
> To: <pljava-dev at lists.pgfoundry.org>
> Sent: Saturday, March 08, 2014 7:21 PM
> Subject: Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
> 
> 
>> Hello,
>> 
>> Is PL/Java safe to use in terms of its threading design?  I've just asked pgsql-hackers about this and am waiting for response, adding the sentence:
>> 
>> "To put the question in other words, is it safe to load a multi-threaded PL library in the single-threaded backend process, if the PL only calls SPI in the main thread?"
>> 
>> My understanding is:
>> 
>> * PL/Java (pljava.so) is linked with the JNI (Java Native Interface) library, libjvm.so, in JRE.  libjvm.so is linked with libpthread.so, because Java VM is multi-threaded.  SO, "ldd pljava.so" shows libjvm.so and libpthread.so. pljava.so doesn't seem to be built for multh-threading ---  none of -mt, -D_REENTRANT or -D_POSIX_C_SOURCE is specified when building it.
>> 
>> * When the application calls Java stored function, pljava.so calls a function in libjvm.so to create a JVM in the backend process, then invokes the user-defined Java method in the main thread.  The user-defined Java method calls JDBC methods to access database.  The JDBC method calls are translated to backend SPI function calls through JNI.
>> 
>> * The main thread can create Java threads using Java Thread API, and those threads can call JDBC methods.  However, PL/Java intercepts JDBC method calls and serializes SPI calls.  So, only one thread calls SPI functions at a time.  I'm wondering if this is the reason why PL/Java is safe for use.
>> 
>> 
>> What I'm concerned about is whether multi-threaded code (Java VM) can run safely in a single-threaded code (postgres).  I cannot point out what can be a particular problem with PL/Java, but in general, the mixture of single-threaded code and multi-threaded one seems to cause trouble around handling errno, memory and file handles/pointers.
>> 
>> FYI, JNI specification says that the code called from Java VM should be built for multi-threading as follows.  But postgres is not.
>> 
>> http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html#wp9502
>> 
>> [Excerpt]
>> Compiling, Loading and Linking Native Methods
>> Since the Java VM is multithreaded, native libraries should also be compiled and linked with multithread aware native compilers. For example, the -mt flag should be used for C++ code compiled with the Sun Studio compiler. For code complied with the GNU gcc compiler, the flags -D_REENTRANT or -D_POSIX_C_SOURCE should be used. For more information please refer to the native compiler documentation.
> 
> _______________________________________________
> Pljava-dev mailing list
> Pljava-dev at lists.pgfoundry.org
> http://lists.pgfoundry.org/mailman/listinfo/pljava-dev



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-03-16 04:05  
  parent: 
  0 siblings, 1 reply; 13+ messages in thread

From:  @ 2014-03-16 04:05 UTC (permalink / raw)

From: "Hal Hildebrand" <hal.hildebrand at me.com>
> So, I really think this question has been definitively answered.

Yes, I found a similar mail thread:

http://postgresql.1045698.n5.nabble.com/doubtful-PL-Java-s-activity-td5783047.html

But I understood that the person who raised the question did not show a test 
case, nor the PL/Java community did not answer why PL/Java has no problem in 
mixing multi-threaded code and single-threaded code.

> If you can produce a test case of your concerns which demonstrates the 
> issue, we can discuss it.

I'd like to do so if I could do it, but I cannot.  This is why I'm asking 
this question.  I want to believe PL/Java has no problem and want to use it. 
I proposed using PL/Java to my colleagues.  However, they are concerned 
about this question.  I want to convince them by showing how PL/Java is safe 
in terms of theory.

> But the simple answer to your question is simply: yes.
> Pl/java obeys the rules and works according to spec.
> It does the right thing in the right way using the best practices.

Could you elaborate on this?  The details should be the answer I'm looking 
for.
As I said as below, it doesn't seem that PL/Java obeys the JNI spec, because 
pljava.so is not compiled with -mt, -D_REENTRANT nor -D_POSIX_C_SOURCE.  In 
short, I'd like to know why it is safe to make JVM to load single-threaded 
pljava.so.

>> FYI, JNI specification says that the code called from Java VM should be 
>> built for multi-threading as follows.  But postgres is not.
>>
>> http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html#wp9502
>>
>> [Excerpt]
>> Compiling, Loading and Linking Native Methods
>> Since the Java VM is multithreaded, native libraries should also be 
>> compiled and linked with multithread aware native compilers. For example, 
>> the -mt flag should be used for C++ code compiled with the Sun Studio 
>> compiler. For code complied with the GNU gcc compiler, the 
>> flags -D_REENTRANT or -D_POSIX_C_SOURCE should be used. For more 
>> information please refer to the native compiler documentation.

Regards
MauMau




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-03-16 05:10  
  parent: 
  0 siblings, 0 replies; 13+ messages in thread

From:  @ 2014-03-16 05:10 UTC (permalink / raw)

On 3/15/2014 9:05 PM, MauMau wrote:
> Could you elaborate on this?  The details should be the answer I'm 
> looking for.
> As I said as below, it doesn't seem that PL/Java obeys the JNI spec, 
> because pljava.so is not compiled with -mt, -D_REENTRANT nor 
> -D_POSIX_C_SOURCE.  In short, I'd like to know why it is safe to make 
> JVM to load single-threaded pljava.so.
>
>>> FYI, JNI specification says that the code called from Java VM should 
>>> be built for multi-threading as follows.  But postgres is not. 
'
JNI has two sides to it.      nonjava stuff calling into java, and Java 
calling into non-java.   pl/java implements the first style, non-java 
code (postgres core) calling java.

-- 
john r pierce                                      37N 122W
somewhere on the middle of the left coast




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-04-13 11:16  
  parent: 
  1 sibling, 1 reply; 13+ messages in thread

From:  @ 2014-04-13 11:16 UTC (permalink / raw)

Hello all,

it seems most likely that I will fail to convince my colleagues to use 
PL/Java.  The performance was not as good as I expected compared to running 
Java functions in a process different from postgres.  On RHEL6 with 
PostgreSQL 9.2.8, I got the following results when I ran 10000 UPDATE 
statements in a single transaction, excluding the time of BEGIN and COMMIT:

* PL/pgSQL: 20 seconds
* PL/Java: 22 seconds (see the attached BatchPL.java for processing)
* Standalone client running on the same server as the database server: 23 
seconds (see Batch.java, which does the same job as BatchPL.java)

I avoided the influence of I/O by setting:

wal_buffers = 16MB
checkpoint_segments = 100
checkpoint_timeout = 1h

So I couldn't insist that PL/Java is required to greatly reduce the overhead 
of interprocess communication and process context switches.  Any ideas?

Regards
MauMau
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Batch.java
Type: application/octet-stream
Size: 1237 bytes
Desc: not available
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20140413/61dea8a8/attachment-0002.obj;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BatchPL.java
Type: application/octet-stream
Size: 1204 bytes
Desc: not available
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20140413/61dea8a8/attachment-0003.obj;



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-04-13 14:47  
  parent: 
  0 siblings, 1 reply; 13+ messages in thread

From:  @ 2014-04-13 14:47 UTC (permalink / raw)

Interesting. What does your call into PL/Java (i.e. the function) look 
like? How often do you call it (I assume just once)?

- thomas

On 2014-04-13 13:16, MauMau wrote:
> Hello all,
>
> it seems most likely that I will fail to convince my colleagues to use 
> PL/Java.  The performance was not as good as I expected compared to 
> running Java functions in a process different from postgres.  On RHEL6 
> with PostgreSQL 9.2.8, I got the following results when I ran 10000 
> UPDATE statements in a single transaction, excluding the time of BEGIN 
> and COMMIT:
>
> * PL/pgSQL: 20 seconds
> * PL/Java: 22 seconds (see the attached BatchPL.java for processing)
> * Standalone client running on the same server as the database server: 
> 23 seconds (see Batch.java, which does the same job as BatchPL.java)
>
> I avoided the influence of I/O by setting:
>
> wal_buffers = 16MB
> checkpoint_segments = 100
> checkpoint_timeout = 1h
>
> So I couldn't insist that PL/Java is required to greatly reduce the 
> overhead of interprocess communication and process context switches.  
> Any ideas?
>
> Regards
> MauMau
>
>
> _______________________________________________
> Pljava-dev mailing list
> Pljava-dev at lists.pgfoundry.org
> http://lists.pgfoundry.org/mailman/listinfo/pljava-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20140413/586f1635/attachment.html;



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-04-13 22:28  
  parent: 
  0 siblings, 1 reply; 13+ messages in thread

From:  @ 2014-04-13 22:28 UTC (permalink / raw)

From: "Thomas Hallgren" <thomas at tada.se>
> Interesting. What does your call into PL/Java (i.e. the function) look
> like? How often do you call it (I assume just once)?

Thank you for your response.  I did:

1. Compiled BatchPL.java with JDK6, then ran "jar cf batch.jar
BatchPL.class".

2. Register the jar file with:
SELECT sqlj.install_jar('file:///some/dir/batch.jar', 'batch', false);

3. Create a Java stored function with:
CREATE FUNCTION batch(integer) RETURNS void
AS 'BatchPL'
LANGUAGE java;

4. Run "SELECT batch(10000);" from psql.


So, I understand that the number of calls from the Java function to PL/Java
is 10000.  I hoped PL/Java reduces the function execution time dramatically
(by half or more) to make my colleagues get interested in PL/Java.

Regards
MauMau





^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-04-14 09:46  
  parent: 
  0 siblings, 1 reply; 13+ messages in thread

From:  @ 2014-04-14 09:46 UTC (permalink / raw)

In some cases the time spent in the actual call overhead is dramatically reduced but far from always. It does depend on 
several factors. Here are a few:

1. A machine with multiple cores may well be able to run the client and server processes more or less 100% in parallel. 
The flow of execution is of course sequential but time spent in context switches will never become an issue.

2. If network latency is very low, then the benefit of using stored procedures for the purpose of minimizing the number 
of calls between client and server is minimal. In some cases it's even better to avoid such procedures since you get a 
better load balance by executing the logic in the client. Context switching is not an issue here either since the 
processes run on different CPUs.

3. For a test like yours, the time it takes to execute the actual statement is important. The execution may be so slow 
that the overhead imposed by the network call becomes negligible. A test using a lightweight "SELECT 1" instead of the 
heavier "UPDATE testtable" would reveal such issues.

4. The complexity of the function. Let's assume that you implement a new custom datatype. The code associated with that 
datatype may potentially be complex and evaluate millions of times when you use it in large tables. Data types affect 
sorting and indexing and may also play a role in the data integrity rules on the database and moving that type of 
responsibility to the client code is often less than ideal. Complex functions written in Java have very good performance.

Items 1-3 are not specific to PL/Java in any way. They apply regardless of procedure language.

- thomas


On 2014-04-14 00:28, MauMau wrote:
> From: "Thomas Hallgren" <thomas at tada.se>
>> Interesting. What does your call into PL/Java (i.e. the function) look
>> like? How often do you call it (I assume just once)?
>
> Thank you for your response.  I did:
>
> 1. Compiled BatchPL.java with JDK6, then ran "jar cf batch.jar
> BatchPL.class".
>
> 2. Register the jar file with:
> SELECT sqlj.install_jar('file:///some/dir/batch.jar', 'batch', false);
>
> 3. Create a Java stored function with:
> CREATE FUNCTION batch(integer) RETURNS void
> AS 'BatchPL'
> LANGUAGE java;
>
> 4. Run "SELECT batch(10000);" from psql.
>
>
> So, I understand that the number of calls from the Java function to PL/Java
> is 10000.  I hoped PL/Java reduces the function execution time dramatically
> (by half or more) to make my colleagues get interested in PL/Java.
>
> Regards
> MauMau
>
>




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-04-14 11:54  
  parent: 
  0 siblings, 2 replies; 13+ messages in thread

From:  @ 2014-04-14 11:54 UTC (permalink / raw)

From: "Thomas Hallgren" <thomas at tada.se>
> 3. For a test like yours, the time it takes to execute the actual 
> statement is important. The execution may be so slow that the overhead 
> imposed by the network call becomes negligible. A test using a lightweight 
> "SELECT 1" instead of the heavier "UPDATE testtable" would reveal such 
> issues.

Yeah, I thought this is the most likely.  We are trying to speed up batch 
jobs dramatically, and I hoped PL/Java's in-process architecture would 
contribute to that.

But I wonder why in-process execution didn't make a big difference.  I 
expected several times of difference because I saw the PollPosition 
benchmark results at http://hsqldb.org/.  It compares HSQLDB's in-process 
and client-server execution models.  I assume the client and the server ran 
on the same host.

Anyway, in-process and out-of-process execution doesn't seem to make a big 
difference for batch jobs which issue many SQL statements.

Regards
MauMau





^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-04-14 12:18  
  parent: 
  1 sibling, 0 replies; 13+ messages in thread

From:  @ 2014-04-14 12:18 UTC (permalink / raw)

On Mon, 14 Apr 2014 20:54:51 +0900
"MauMau" <maumau307 at gmail.com> wrote:
> Anyway, in-process and out-of-process execution doesn't seem to make a big 
> difference for batch jobs which issue many SQL statements.

That reminds me of a MOSIX tip... Could an out-of-process execution to be able to
get better performances from a multi processor setup?

-- 
Alberto Cabello S?nchez
<alberto at unex.es>



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process?
@ 2014-04-14 19:32  
  parent: 
  1 sibling, 0 replies; 13+ messages in thread

From:  @ 2014-04-14 19:32 UTC (permalink / raw)

On 2014-04-14 13:54, MauMau wrote:
> From: "Thomas Hallgren" <thomas at tada.se>
>> 3. For a test like yours, the time it takes to execute the actual 
>> statement is important. The execution may be so slow that the 
>> overhead imposed by the network call becomes negligible. A test using 
>> a lightweight "SELECT 1" instead of the heavier "UPDATE testtable" 
>> would reveal such issues.
>
>
> But I wonder why in-process execution didn't make a big difference.

But that's my point. It may well make a big difference but you don't see 
it because your tests are using an update statement. The update will do 
index lookups and physical writes to disk! This means that the update 
consumes perhaps 90% or more of the overall time, regardless of what 
calling mechanism you use. Its not a good choice if you want to measure 
calling mechanism differences.

- thomas



^ permalink  raw  reply  [nested|flat] 13+ messages in thread


end of thread, other threads:[~2014-04-14 19:32 UTC | newest]

Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-03-08 10:21 [Pljava-dev] Is it safe to use multi-threaded PL/Java in single-threaded postgres process? 
2014-03-09 11:06 ` 
2014-03-16 01:56 ` 
2014-03-16 02:04   ` 
2014-03-16 04:05     ` 
2014-03-16 05:10       ` 
2014-04-13 11:16   ` 
2014-04-13 14:47     ` 
2014-04-13 22:28       ` 
2014-04-14 09:46         ` 
2014-04-14 11:54           ` 
2014-04-14 12:18             ` 
2014-04-14 19:32             ` 

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox