Repository navigation
Release resources with "Discard All" when return connection into pool - #54
Conversation
|
Hi, franciscojunior. I have merged #52. Please check it again. |
|
Hi, @ChenHuajun . I'll check it. Thanks! |
|
Sorry for late reply. Excellent work, @ChenHuajun ! I'm finishing some tests here and will merge your pr soon. |
|
Hi @skykiker / @ChenHuajun Francisco wanted me to review and comment on your changes to NpgsqlStartupPacket.cs, because it seems to revert some optimizations that were recently added. First of all, we both like the way you've encapsulated the v2 and v3 functionality in subclasses. I notice that your PR reverts back to storing strings (database_name, user_name, etc.) rather than byte[]. I switched to byte[] as part of an optimization package. If there is a compelling reason to go back to strings, I'm not seeing it. Your approach to writing the v3 packet to the backend stream is inefficient, because the use of an intermediate buffer results in extra memory consumption and two new copy operations (once to byte[], then again to the backend stream). Recent changes aimed at making those operations as efficient as possible. What you could do instead of the intermediate buffer, is to scan parameters once to determine total packet length, and then again to write its values directly to the backend stream. If you change parameters from (Dictionary<string, string>) to (Dictionary<byte[], byte[]>), moving the UTF8 encoding operations to BuildStartupPacket(), scanning to determine lengths will be very efficient, and memory footprint will be reduced further. I also notice that your scan of parameters could be a little more efficient by doing (foreach (KeyValuePair<> param in parameters)). One last comment... It looks to me like protocol_version, database_name, and user_name could be moved to NpgsqlStartupPacket{}, eliminating duplication. What do you think? |
|
Hi @glenebob Thanks for your comment. |
|
Excellent work, @ChenHuajun / @skykiker . I tested your PR here and everything is ok. I'm just waiting @glenebob say if he thinks there is any other change needed. If not, I'll merge it. |
|
@glenebob says merge away :) |
|
Merge it is, sir! |
Release resources with "Discard All" when return connection into pool I had made a new patch to release resources clearly with "Discard ALL" when return a connection into the pool,which is based on the following discussion. http://pgfoundry.org/tracker/index.php?func=detail&aid=1011241&group_id=1000140&atid=592 The major modificaions is as the following 1)Release resources with "Discard ALL" if the backend is 8.3 or later and the protocol is V3. "Discard ALL" is introduced since 8.3 and it is not able to set session configulations via starup package while use protocol V2. So keep their behaviors as before. 2)Refactor the code to send starup package. When use protocol V3,set session configulations via starup package,other than execute "set xxxx=yyy" later. 3)Add a test case Regards, Chen Huajun
|
Hi, @ChenHuajun / @skykiker . After merging your work, I noticed a little problem regarding extra_floating_digits parameter. This error only appears in postgresql below 9.0 where the max extra_floating_digits support was changed from 2 to 3. This is the error I'm getting on postgreql 8.4: NpgsqlTests.ConnectionTests (TestFixtureSetUp): Before this patch, this situation was handled by asking the server to set the extra_float_digits to 2 and then to 3. If the 3 wasn't supported, an exception was generated by the value of 2 was already set. Today, with your patch, I noticed that asking the server to use a value of 2 was removed. Only the value of 3 is asked. It was my fault that I didn't test on postgresql 8.4. Please, give it a try on postgresql 8.4. Thanks in advance. |
|
Hi Francisco, |
|
Hi ChenHuajun! No problem. It was also my fault because I didn't test it with Postgresql 8.4. But when using method a, the maximum extra_floating_digits will be 2? and the test case: I remember we received some complaints about the number of floating digits in Npgsql. That's why we need to keep the number of floating points to 3 where available. I'm more inclined towards method b) unless we can check for sure if 2 digits would be enough as the guys from pgjdbc are doing it. Unless they "forgot" to handle the case of 3 digits which I think is unlikely. |
|
Hi, @ChenHuajun ! I fixed a problem with extra_float_digits when running Npgsql under postgresql below 9.0. This fix is in the pull request #69 . After working on this fix, I noticed that using extra_float_digits value of 2 makes the test pass too, so I'm thinking that your method a) of using a value of 2 for all connections is probably the best idea. I would just need to check if I can find the user report where the value of 3 was needed. If I can't find this report, I think you can create a new pull request with your changes like in the method a) What do you think? |
|
Hi, @francisco! And since it's not sure whether using extra_float_digits value of 2 is enough,just behave as before seems to be a better choose.So, i'm inclined towards that set extra_float_digits to 2 via startup package first,then set extra_float_digits to 3 via SET command while the backend is PostgreSQL 9.0+,do your agree? Moreover i found there are some conflicts between #69 and this patch,so i want to make a new patch after #69 has been merged. |
Hi Francisco,
I had made a new patch to release resources clearly with "Discard ALL" when return a connection into the pool,which is based on the following discussion.
http://pgfoundry.org/tracker/index.php?func=detail&aid=1011241&group_id=1000140&atid=592
The major modificaions is as the following
1)Release resources with "Discard ALL" if the backend is 8.3 or later and the protocol is V3.
"Discard ALL" is introduced since 8.3 and it is not able to set session configulations via starup package while use protocol V2. So keep their behaviors as before.
2)Refactor the code to send starup package.
When use protocol V3,set session configulations via starup package,other than execute "set xxxx=yyy" later.
3)Add a test case
Regards,
Chen Huajun