Skip to content

Release connection into pool with "Discard All"(new) - #74

Merged
franciscojunior merged 3 commits into
npgsql:masterfrom
ChenHuajun:discardall2
Oct 31, 2013
Merged

franciscojunior merged 3 commits into
npgsql:masterfrom
ChenHuajun:discardall2

Conversation

@ChenHuajun

Copy link
Copy Markdown
Contributor

Hi,francisco
This is a new patch to replace #54,please give a look.

I had tested it for PG8.4 and PG9.2,all cases passed.And the performance also look like before.

run test cases without this pacth:
tests runs:645
Time:52.936

run test cases with this pacth:
tests runs:647
Time:52.897

Chen Huajun

@roji

roji commented Oct 8, 2013

Copy link
Copy Markdown
Member

Just a small comment...

Measuring the total running time of the Npgsql unit tests doesn't really say much about performance - none of the tests do any serious processing and 99% of the time is probably spent connecting and disconnecting.

A better approach would be to write a speed test in SpeedTests.cs specifically to measure what you want...

@ChenHuajun

Copy link
Copy Markdown
Contributor Author

It's a good idea.The patch only impacts connect and disconnect.So i add two speed tests, one with pool another without pool.
When not using pool,this patch is more efficient.But when using pool, there is a slight performance down(2ms->3ms one time).The reason is that resource releasing in this patch need to execute two command("discard all" and "SET extra_float_digits=3" ) and the current source only execute one command("unlisten *").One command executing need about 1ms,almost of the time is spent tcp communication.I tried to execute "discard all;SET extra_float_digits=3" to reduce communication time,but postgresql fail to execute discard all in a muti-statment.

In fact current resource releasing need _planIndex+1 commands.So when _planIndex is large than 1 this patch will be more efficient.
And 1 ms is not big delay,so performance seem not to be a problem.

---------------------------result of speed tests---------------------------------------
run test cases without this pacth:
***** NpgsqlTests.SpeedTests.ConnectWithoutPool
connect/disconnect time: 77303ms
Total test running time: 77306ms
***** NpgsqlTests.SpeedTests.ConnectWithPool
connect/disconnect time: 21172ms
Total test running time: 21172ms

run test cases without this pacth:
***** NpgsqlTests.SpeedTests.ConnectWithoutPool
connect/disconnect time: 59143ms
Total test running time: 59144ms
***** NpgsqlTests.SpeedTests.ConnectWithPool
connect/disconnect time: 30314ms
Total test running time: 30315ms

@franciscojunior

Copy link
Copy Markdown
Member

I have two suggestions:

  1. Add a notice before the if protocol version == 2 saying that those connection parameters for protocol 3 are now being sent in the startup packet.
  2. Instead of having a set extra_float_digits inside the if and in the else, I think we can put the set extra floating outside the if protocol version. This way it would be executed regardless of the protocol. What do you think?

@ChenHuajun

Copy link
Copy Markdown
Contributor Author

have done

@franciscojunior

Copy link
Copy Markdown
Member

Great!

But I still got a problem. :(

When the connection is taken back from the pool, the extra_float_digits parameter is reset by the discard all and I get an error in the Bug10992DoubleValueSupport test.

I think this can be reverted by re adding the extra_float_digits=2 parameter in the startup packet.

@ChenHuajun

Copy link
Copy Markdown
Contributor Author

I reverted the last commit and add a comment. Because while had set extra_float_digits=2 parameter in the startup packet,do not need set it again in postgresql8,4 . If "put the set extra floating outside the if protocol version" we had to set extra_float_digits=2 twice in postgresql8,4 , or check protocol version again.

@franciscojunior

Copy link
Copy Markdown
Member

Great!

Now, I got another problem :(

While I did a last test in my dev machine, I noticed that it is complaining about an unrecognized configuration parameter:


LOG:  connection received: host=127.0.0.1 port=52221
LOG:  connection authorized: user=npgsql_tests database=npgsql_tests
FATAL:  unrecognized configuration parameter "ssl_renegotiation_limit"

This is happening because my postgresql 8.4.1 doesn't have support for this parameter setting. So, with this patch, if Npgsql is used in a server which doesn't have this parameter support, it will always fail to connect. :(

According to Npgsql code comment about this parameter, ( the link in the comment is wrong. It has been changed) I talked about this parameter change on this mail http://lists.pgfoundry.org/pipermail/npgsql-devel/2010-February/001074.html The following versions have support for this parameter:

"[...] The fix has been backpatched all the way to 7.4, so the following versions
will have the new parameter:
9.0, 8.4.3, 8.3.10, 8.2.16, 8.1.20, 8.0.24, 7.4.28"

We need to check how to handle that.

@ChenHuajun

Copy link
Copy Markdown
Contributor Author

According the link ssl_renegotiation_limit was setted to avoid a bug in Mono.Security.dll. Does this bug still exists?
If not we can remove this paramater simply.
If we must set ssl_renegotiation_limit, the only approche can run in all version of postgres after 7.4 is SET command,for optimizing we can only set ssl_renegotiation_limit when using ssl.

@franciscojunior

Copy link
Copy Markdown
Member

Yes, this bug still exist. Also, in fact, this parameter is also used to prevent a bug in ssl libraries used in the Postgresql itself (http://www.postgresql.org/message-id/[email protected])
Full discussion about this parameter in Npgsql: http://lists.pgfoundry.org/pipermail/npgsql-devel/2010-February/001074.html

Npgsql already have support to use SSLStream class instead of Mono libraries, but it is still optional. The user has to request explicitly to use it.

I agree with you that we will have to use the set command and we can even optimize it to be set only when ssl is being used. But this would imply in more checks after the "discard all"

Would you mind to make those changes in your pull request? Also, after the last merges I did yesterday, it needs to be rebased. Thanks in advance.

We will need to talk about how to handle those set commands we need to send after "discard all" command. I'm starting to think we could use an initalization vector with all the set parameters needed to be sent at a time. For example:

Npgsql calls discard all
then, when the connection is taken from the pool, this initialization vector is called:
"set extra_float_digits=3;set ssl_renegotiation_limit=0;set encoding=utf8;set datetimestyle=ISO;" etc, etc

We could create this initialization vector when the connection starts and reuse it whenever we get a new connection from the pool. This way "discard all" can be used without worrying about which other parameters have to be set after it.
What do you think?

@glenebob glenebob mentioned this pull request Oct 15, 2013
@ChenHuajun

Copy link
Copy Markdown
Contributor Author

I agree with your. And it's needed to make sure that there is no error in any of parameters setting when combining them into one command.

I noticed when executing "SET lc_monetary='C'" ,the exception was ignored in the current source. Do this means some version of PostgreSQL do not support "SET lc_monetary='C'"? If so we must execute "SET lc_monetary='C'" in individual command.

@ChenHuajun

Copy link
Copy Markdown
Contributor Author

Hi,francisco
I had rebased my patch and modified as you suggested,please check it again.
BTW,now we can get a little performance promotion with this patch in connect/disconnect according my test.

franciscojunior added a commit that referenced this pull request Oct 31, 2013
Release connection into pool with "Discard All"(new)
@franciscojunior
franciscojunior merged commit 7f6b2fd into npgsql:master Oct 31, 2013
@franciscojunior

Copy link
Copy Markdown
Member

Sorry I didn't answer your question before.

I think the set lc_monetary code is wrapped in the try catch because I copied it from the other settings part :)
From my understanding, all postgresql versions support lc_monetary='C' as it is the one set when no locale is specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants