Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
b1d6d788
Commit
b1d6d788
authored
Mar 19, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kill pendingCount; redundant - risks being incorrect
parent
d4be9a3b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
16 deletions
+14
-16
MessageQueue.cs
StackExchange.Redis/StackExchange/Redis/MessageQueue.cs
+2
-1
PhysicalBridge.cs
StackExchange.Redis/StackExchange/Redis/PhysicalBridge.cs
+12
-15
No files found.
StackExchange.Redis/StackExchange/Redis/MessageQueue.cs
View file @
b1d6d788
...
@@ -45,11 +45,12 @@ public Message PeekPing(out int queueLength)
...
@@ -45,11 +45,12 @@ public Message PeekPing(out int queueLength)
return
null
;
return
null
;
}
}
public
void
Push
(
Message
message
)
public
bool
Push
(
Message
message
)
{
{
lock
(
regular
)
lock
(
regular
)
{
{
(
message
.
IsHighPriority
?
high
:
regular
).
Enqueue
(
message
);
(
message
.
IsHighPriority
?
high
:
regular
).
Enqueue
(
message
);
return
high
.
Count
+
regular
.
Count
==
1
;
}
}
}
}
...
...
StackExchange.Redis/StackExchange/Redis/PhysicalBridge.cs
View file @
b1d6d788
...
@@ -25,7 +25,6 @@ private static readonly Message
...
@@ -25,7 +25,6 @@ private static readonly Message
volatile
bool
isDisposed
;
volatile
bool
isDisposed
;
//private volatile int missedHeartbeats;
//private volatile int missedHeartbeats;
private
long
operationCount
,
socketCount
;
private
long
operationCount
,
socketCount
;
private
int
pendingCount
;
private
volatile
PhysicalConnection
physical
;
private
volatile
PhysicalConnection
physical
;
...
@@ -116,7 +115,6 @@ public bool TryEnqueue(Message message, bool isSlave)
...
@@ -116,7 +115,6 @@ public bool TryEnqueue(Message message, bool isSlave)
// you can go in the queue, but we won't be starting
// you can go in the queue, but we won't be starting
// a worker, because the handshake has not completed
// a worker, because the handshake has not completed
queue
.
Push
(
message
);
queue
.
Push
(
message
);
Interlocked
.
Increment
(
ref
pendingCount
);
return
true
;
return
true
;
}
}
else
else
...
@@ -126,12 +124,11 @@ public bool TryEnqueue(Message message, bool isSlave)
...
@@ -126,12 +124,11 @@ public bool TryEnqueue(Message message, bool isSlave)
}
}
}
}
queue
.
Push
(
message
);
bool
reqWrite
=
queue
.
Push
(
message
);
LogNonPreferred
(
message
.
Flags
,
isSlave
);
LogNonPreferred
(
message
.
Flags
,
isSlave
);
int
newPendingCount
=
Interlocked
.
Increment
(
ref
pendingCount
);
Trace
(
"Now pending: "
+
GetPendingCount
());
Trace
(
"Now pending: "
+
newPendingCount
);
if
(
newPendingCount
==
1
)
if
(
reqWrite
)
{
{
multiplexer
.
RequestWrite
(
this
,
false
);
multiplexer
.
RequestWrite
(
this
,
false
);
}
}
...
@@ -336,7 +333,7 @@ internal void OnFullyEstablished(PhysicalConnection connection)
...
@@ -336,7 +333,7 @@ internal void OnFullyEstablished(PhysicalConnection connection)
}
}
internal
int
GetPendingCount
()
internal
int
GetPendingCount
()
{
{
return
Thread
.
VolatileRead
(
ref
pendingCount
);
return
queue
.
Count
(
);
}
}
internal
void
OnHeartbeat
()
internal
void
OnHeartbeat
()
{
{
...
@@ -358,8 +355,8 @@ internal void OnHeartbeat()
...
@@ -358,8 +355,8 @@ internal void OnHeartbeat()
var
tmp
=
physical
;
var
tmp
=
physical
;
if
(
tmp
!=
null
)
if
(
tmp
!=
null
)
{
{
int
writeEvery
=
serverEndPoint
.
WriteEverySeconds
;
int
writeEvery
Seconds
=
serverEndPoint
.
WriteEverySeconds
;
if
(
writeEvery
>
0
&&
tmp
.
LastWriteSecondsAgo
>=
writeEvery
&&
Thread
.
VolatileRead
(
ref
pendingCount
)
==
0
)
if
(
writeEvery
Seconds
>
0
&&
tmp
.
LastWriteSecondsAgo
>=
writeEverySeconds
)
{
{
Trace
(
"OnHeartbeat - overdue"
);
Trace
(
"OnHeartbeat - overdue"
);
if
(
state
==
(
int
)
State
.
ConnectedEstablished
)
if
(
state
==
(
int
)
State
.
ConnectedEstablished
)
...
@@ -417,16 +414,16 @@ internal bool TryEnqueue(List<Message> messages, bool isSlave)
...
@@ -417,16 +414,16 @@ internal bool TryEnqueue(List<Message> messages, bool isSlave)
{
{
return
false
;
return
false
;
}
}
bool
reqWrite
=
false
;
foreach
(
var
message
in
messages
)
foreach
(
var
message
in
messages
)
{
// deliberately not taking a single lock here; we don't care if
{
// deliberately not taking a single lock here; we don't care if
// other threads manage to interleave - in fact, it would be desirable
// other threads manage to interleave - in fact, it would be desirable
// (to avoid a batch monopolising the connection)
// (to avoid a batch monopolising the connection)
queue
.
Push
(
message
)
;
if
(
queue
.
Push
(
message
))
reqWrite
=
true
;
LogNonPreferred
(
message
.
Flags
,
isSlave
);
LogNonPreferred
(
message
.
Flags
,
isSlave
);
}
}
int
newPendingCount
=
Interlocked
.
Add
(
ref
pendingCount
,
messages
.
Count
);
Trace
(
"Now pending: "
+
GetPendingCount
());
Trace
(
"Now pending: "
+
newPendingCount
);
if
(
reqWrite
)
// was empty before
if
(
newPendingCount
==
messages
.
Count
)
// was empty before
{
{
multiplexer
.
RequestWrite
(
this
,
false
);
multiplexer
.
RequestWrite
(
this
,
false
);
}
}
...
@@ -679,8 +676,8 @@ internal WriteResult WriteQueue(int maxWork)
...
@@ -679,8 +676,8 @@ internal WriteResult WriteQueue(int maxWork)
return
WriteResult
.
QueueEmpty
;
return
WriteResult
.
QueueEmpty
;
}
}
last
=
next
;
last
=
next
;
var
newPendingCount
=
Interlocked
.
Decrement
(
ref
pendingCount
);
Trace
(
"Now pending: "
+
newPendingCount
);
Trace
(
"Now pending: "
+
GetPendingCount
()
);
WriteMessageDirect
(
conn
,
next
);
WriteMessageDirect
(
conn
,
next
);
count
++;
count
++;
if
(
maxWork
>
0
&&
count
>=
maxWork
)
if
(
maxWork
>
0
&&
count
>=
maxWork
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment