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
74f81517
Commit
74f81517
authored
Jul 25, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attempt 4 at forcing a protocol corruption problem :(
parent
6b351b86
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
10 deletions
+83
-10
Program.cs
TestConsole/Program.cs
+83
-10
No files found.
TestConsole/Program.cs
View file @
74f81517
using
System
;
using
System
;
using
System.Net
;
using
System.Net
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StackExchange.Redis
.Server
;
using
StackExchange.Redis
;
static
class
Program
static
class
Program
{
{
static
async
Task
Main
()
static
async
Task
Main
()
{
{
//using (var pool = new Pipelines.Sockets.Unofficial.DedicatedThreadPoolPipeScheduler(minWorkers: 10, maxWorkers: 50,
const
int
ClientCount
=
50
;
// priority: System.Threading.ThreadPriority.Highest))
CancellationTokenSource
cancel
=
new
CancellationTokenSource
();
using
(
var
resp
=
new
MemoryCacheRedisServer
(
Console
.
Out
))
using
(
var
socket
=
new
RespSocketServer
(
resp
))
var
config
=
new
ConfigurationOptions
{
EndPoints
=
{
new
IPEndPoint
(
IPAddress
.
Loopback
,
6379
)
}
};
using
(
var
muxer
=
await
ConnectionMultiplexer
.
ConnectAsync
(
config
))
{
var
tasks
=
new
Task
[
ClientCount
+
1
];
tasks
[
0
]
=
Task
.
Run
(()
=>
ShowState
(
cancel
.
Token
));
for
(
int
i
=
1
;
i
<
tasks
.
Length
;
i
++)
{
int
seed
=
i
;
var
key
=
"test_client_"
+
i
;
tasks
[
i
]
=
Task
.
Run
(()
=>
RunClient
(
key
,
seed
,
muxer
,
cancel
.
Token
));
}
Console
.
ReadLine
();
cancel
.
Cancel
();
await
Task
.
WhenAll
(
tasks
);
}
}
static
int
success
,
failure
,
clients
;
static
long
bytesChecked
;
static
async
Task
ShowState
(
CancellationToken
cancellation
)
{
while
(!
cancellation
.
IsCancellationRequested
)
{
await
Task
.
Delay
(
2000
);
Console
.
WriteLine
(
$"[
{
Thread
.
VolatileRead
(
ref
clients
)}
] Success:
{
Thread
.
VolatileRead
(
ref
success
)}
, Failure:
{
Thread
.
VolatileRead
(
ref
failure
)}
, Bytes:
{
Format
(
Thread
.
VolatileRead
(
ref
bytesChecked
))}
"
);
}
}
static
string
Format
(
long
value
)
{
if
(
value
<
1024
)
return
value
+
" B"
;
if
(
value
<
(
1024
*
1024
))
return
(
value
>>
10
)
+
" KiB"
;
if
(
value
<
(
1024
*
1024
*
1024
))
return
(
value
>>
20
)
+
" MiB"
;
return
(
value
>>
30
)
+
" GiB"
;
}
static
async
Task
RunClient
(
RedisKey
key
,
int
seed
,
ConnectionMultiplexer
client
,
CancellationToken
cancellation
)
{
Interlocked
.
Increment
(
ref
clients
);
try
{
var
rand
=
new
Random
(
seed
);
byte
[]
payload
=
new
byte
[
65536
];
while
(!
cancellation
.
IsCancellationRequested
)
{
var
db
=
client
.
GetDatabase
(
rand
.
Next
(
0
,
10
));
rand
.
NextBytes
(
payload
);
int
len
=
rand
.
Next
(
1024
,
payload
.
Length
);
var
memory
=
new
ReadOnlyMemory
<
byte
>(
payload
,
0
,
len
);
var
set
=
db
.
StringSetAsync
(
key
,
memory
);
var
get
=
db
.
StringGetAsync
(
key
);
await
set
;
ReadOnlyMemory
<
byte
>
result
=
await
get
;
Interlocked
.
Add
(
ref
bytesChecked
,
len
);
if
(
memory
.
Span
.
SequenceEqual
(
result
.
Span
))
{
Interlocked
.
Increment
(
ref
success
);
}
else
{
Interlocked
.
Increment
(
ref
failure
);
Console
.
Error
.
WriteLine
(
"Expectation failed on "
+
key
.
ToString
());
}
}
}
catch
(
Exception
ex
)
{
Console
.
Error
.
WriteLine
(
ex
.
Message
);
}
finally
{
{
//var options = new PipeOptions(readerScheduler: pool, writerScheduler: pool, useSynchronizationContext: false);
Interlocked
.
Decrement
(
ref
clients
);
socket
.
Listen
(
new
IPEndPoint
(
IPAddress
.
Loopback
,
6378
)
// , sendOptions: options, receiveOptions: options
);
await
resp
.
Shutdown
;
}
}
}
}
}
}
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