Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
d6a2d5ea
E
et
项目概览
老鱼er
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
et
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d6a2d5ea
编写于
2月 12, 2018
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ActorTask改成struct,减少堆内存分配
上级
93b10eca
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
41 addition
and
95 deletion
+41
-95
Server/Model/Module/Actor/ActorProxy.cs
Server/Model/Module/Actor/ActorProxy.cs
+12
-86
Server/Model/Module/Actor/ActorTask.cs
Server/Model/Module/Actor/ActorTask.cs
+29
-0
Server/Model/Module/DB/DBTask.cs
Server/Model/Module/DB/DBTask.cs
+0
-9
未找到文件。
Server/Model/Module/Actor/ActorProxy.cs
浏览文件 @
d6a2d5ea
...
...
@@ -3,78 +3,9 @@ using System.Collections.Generic;
using
System.Net
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
MongoDB.Bson.Serialization.Attributes
;
namespace
Model
{
public
abstract
class
ActorTask
{
[
BsonIgnore
]
public
ActorProxy
proxy
;
[
BsonElement
]
public
MessageObject
message
;
public
abstract
Task
<
IResponse
>
Run
();
public
abstract
void
RunFail
(
int
error
);
}
/// <summary>
/// 普通消息,不需要response
/// </summary>
public
class
ActorMessageTask
:
ActorTask
{
public
ActorMessageTask
(
ActorProxy
proxy
,
IMessage
message
)
{
this
.
proxy
=
proxy
;
this
.
message
=
(
MessageObject
)
message
;
}
public
override
async
Task
<
IResponse
>
Run
()
{
ActorRequest
request
=
new
ActorRequest
()
{
Id
=
this
.
proxy
.
Id
,
AMessage
=
this
.
message
};
ActorResponse
response
=
(
ActorResponse
)
await
this
.
proxy
.
RealCall
(
request
,
this
.
proxy
.
CancellationTokenSource
.
Token
);
return
response
;
}
public
override
void
RunFail
(
int
error
)
{
}
}
/// <summary>
/// Rpc消息,需要等待返回
/// </summary>
public
class
ActorRpcTask
:
ActorTask
{
[
BsonIgnore
]
public
readonly
TaskCompletionSource
<
IResponse
>
Tcs
=
new
TaskCompletionSource
<
IResponse
>();
public
ActorRpcTask
(
ActorProxy
proxy
,
IMessage
message
)
{
this
.
proxy
=
proxy
;
this
.
message
=
(
MessageObject
)
message
;
}
public
override
async
Task
<
IResponse
>
Run
()
{
ActorRequest
request
=
new
ActorRequest
()
{
Id
=
this
.
proxy
.
Id
,
AMessage
=
this
.
message
};
ActorResponse
response
=
(
ActorResponse
)
await
this
.
proxy
.
RealCall
(
request
,
this
.
proxy
.
CancellationTokenSource
.
Token
);
if
(
response
.
Error
!=
ErrorCode
.
ERR_NotFoundActor
)
{
this
.
Tcs
.
SetResult
((
IResponse
)
response
.
AMessage
);
}
return
response
;
}
public
override
void
RunFail
(
int
error
)
{
this
.
Tcs
.
SetException
(
new
RpcException
(
error
,
""
));
}
}
[
ObjectSystem
]
public
class
ActorProxySystem
:
ObjectSystem
<
ActorProxy
>,
IAwake
,
IStart
{
...
...
@@ -118,8 +49,6 @@ namespace Model
public
void
Awake
()
{
this
.
LastSendTime
=
TimeHelper
.
Now
();
this
.
RunningTasks
.
Clear
();
this
.
WaitingTasks
.
Clear
();
this
.
WindowSize
=
1
;
this
.
tcs
=
null
;
this
.
CancellationTokenSource
=
new
CancellationTokenSource
();
...
...
@@ -140,7 +69,7 @@ namespace Model
this
.
failTimes
=
0
;
var
t
=
this
.
tcs
;
this
.
tcs
=
null
;
t
?.
SetResult
(
n
ull
);
t
?.
SetResult
(
n
ew
ActorTask
()
);
}
public
async
void
Start
()
...
...
@@ -165,12 +94,6 @@ namespace Model
}
}
private
void
Remove
()
{
this
.
RunningTasks
.
Dequeue
();
this
.
AllowGet
();
}
private
void
AllowGet
()
{
if
(
this
.
tcs
==
null
||
this
.
WaitingTasks
.
Count
<=
0
||
this
.
RunningTasks
.
Count
>=
this
.
WindowSize
)
...
...
@@ -208,10 +131,6 @@ namespace Model
{
return
;
}
if
(
actorTask
==
null
)
{
return
;
}
try
{
this
.
RunTask
(
actorTask
);
...
...
@@ -273,7 +192,9 @@ namespace Model
{
++
this
.
WindowSize
;
}
this
.
Remove
();
this
.
RunningTasks
.
Dequeue
();
this
.
AllowGet
();
}
catch
(
Exception
e
)
{
...
...
@@ -283,13 +204,18 @@ namespace Model
public
void
Send
(
IMessage
message
)
{
ActorMessageTask
task
=
new
ActorMessageTask
(
this
,
message
);
ActorTask
task
=
new
ActorTask
();
task
.
message
=
(
MessageObject
)
message
;
task
.
proxy
=
this
;
this
.
Add
(
task
);
}
public
Task
<
IResponse
>
Call
(
IRequest
request
)
{
ActorRpcTask
task
=
new
ActorRpcTask
(
this
,
request
);
ActorTask
task
=
new
ActorTask
();
task
.
message
=
(
MessageObject
)
request
;
task
.
proxy
=
this
;
task
.
Tcs
=
new
TaskCompletionSource
<
IResponse
>();
this
.
Add
(
task
);
return
task
.
Tcs
.
Task
;
}
...
...
Server/Model/Module/Actor/ActorTask.cs
0 → 100644
浏览文件 @
d6a2d5ea
using
System.Threading.Tasks
;
namespace
Model
{
public
struct
ActorTask
{
public
ActorProxy
proxy
;
public
MessageObject
message
;
public
TaskCompletionSource
<
IResponse
>
Tcs
;
public
async
Task
<
IResponse
>
Run
()
{
ActorRequest
request
=
new
ActorRequest
()
{
Id
=
this
.
proxy
.
Id
,
AMessage
=
this
.
message
};
ActorResponse
response
=
(
ActorResponse
)
await
this
.
proxy
.
RealCall
(
request
,
this
.
proxy
.
CancellationTokenSource
.
Token
);
if
(
response
.
Error
!=
ErrorCode
.
ERR_NotFoundActor
)
{
this
.
Tcs
?.
SetResult
((
IResponse
)
response
.
AMessage
);
}
return
response
;
}
public
void
RunFail
(
int
error
)
{
this
.
Tcs
?.
SetException
(
new
RpcException
(
error
,
""
));
}
}
}
\ No newline at end of file
Server/Model/Module/DB/DBTask.cs
浏览文件 @
d6a2d5ea
...
...
@@ -4,15 +4,6 @@ namespace Model
{
public
abstract
class
DBTask
:
Component
{
protected
DBTask
()
{
}
protected
DBTask
(
long
id
)
{
this
.
Id
=
id
;
}
public
abstract
Task
Run
();
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录