Skip to content

fix_event_counters_2: another way for fix 3480#3481

Closed
neyromant wants to merge 1 commit intonpgsql:mainfrom
neyromant:fix_event_counters_2
Closed

fix_event_counters_2: another way for fix 3480#3481
neyromant wants to merge 1 commit intonpgsql:mainfrom
neyromant:fix_event_counters_2

Conversation

@neyromant
Copy link
Contributor

@neyromant neyromant commented Jan 27, 2021

Alternative approach to fix #3480

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I indeed like the approach of just using the existing logic in GetPoolAndSettings to determine when a new pool (actually) gets created.

One point re HashSet vs. array... This is a cold code path where performance isn't a concern: pools seldom get added (and should seldom get removed once #3396 is implemented), and the actual iteration in GetIdleConnection/GetBusyConnections happens once per second, at the very most.

So I'd prefer a simple HashSet protected by a simple lock, rather than this more complicated logic. Note that a lock is already being used when adding (because it may grow), and likely will be needed when pools are removed after #3396. Basically no reason not to keep it simple.

@vonzshik any thoughts?

Copy link
Contributor

@vonzshik vonzshik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like this more than the previous one. There is one place which I'm unsure of, but overall it does look good.

@neyromant
Copy link
Contributor Author

neyromant commented Jan 27, 2021

@roji About Hashset... In the GetIdleConnection / GetBusyConnections methods, we will have to iterate Hashset's items. Potentially, an addition / deletion to Hashset can occur at that moment. This will throw an exception or am I wrong?
Of course we can wrap GetIdleConnection / GetBusyConnections in a lock, but do we need this kind of overhead?

@YohDeadfall
Copy link
Contributor

@neyromant, it will throw like other non concurrent collections (except arrays) because all of them has a version inside it in the iterator. If they ain't equal, the iterator throws.

@roji
Copy link
Member

roji commented Jan 27, 2021

@neyromant yes, above I was proposing to protect all accesses to the hashset with a lock. Event counters are polled at most once per second, and contention is likely to be zero - so I don't see how this would add any overhead or perf issues.

@neyromant neyromant mentioned this pull request Jan 28, 2021
@neyromant
Copy link
Contributor Author

@neyromant yes, above I was proposing to protect all accesses to the hashset with a lock. Event counters are polled at most once per second, and contention is likely to be zero - so I don't see how this would add any overhead or perf issues.

@roji I have created PR #3485 - using HashSet and lock. Should I close #3476 and #3481?

@roji
Copy link
Member

roji commented Jan 28, 2021

Should I close #3476 and #3481?

@neyromant I think so, I think we're going down that way and just have to sort out the locking.

@neyromant
Copy link
Contributor Author

Fixed in #3485

@neyromant neyromant closed this Jan 28, 2021
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.

Busy/idle connection event counters are incorrect around multiple versions of the same connection string

4 participants