Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
e9174896
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e9174896
编写于
9月 07, 2019
作者:
W
wxyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MS-511 Update resource_test in scheduler
Former-commit-id: 9a3ca7eeb8c0043686aef01cf93d899a4b98c894
上级
9af8a46f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
176 addition
and
22 deletion
+176
-22
cpp/CHANGELOG.md
cpp/CHANGELOG.md
+1
-0
cpp/src/scheduler/resource/Resource.h
cpp/src/scheduler/resource/Resource.h
+2
-7
cpp/src/scheduler/resource/TestResource.cpp
cpp/src/scheduler/resource/TestResource.cpp
+33
-0
cpp/src/scheduler/resource/TestResource.h
cpp/src/scheduler/resource/TestResource.h
+38
-0
cpp/src/scheduler/task/Task.h
cpp/src/scheduler/task/Task.h
+1
-0
cpp/unittest/scheduler/resource_test.cpp
cpp/unittest/scheduler/resource_test.cpp
+101
-15
未找到文件。
cpp/CHANGELOG.md
浏览文件 @
e9174896
...
...
@@ -97,6 +97,7 @@ Please mark all change in change log and use the ticket from JIRA.
-
MS-504 - Update node_test in scheduler
-
MS-505 - Install core unit test and add to coverage
-
MS-508 - Update normal_test in scheduler
-
MS-511 - Update resource_test in scheduler
## New Feature
-
MS-343 - Implement ResourceMgr
...
...
cpp/src/scheduler/resource/Resource.h
浏览文件 @
e9174896
...
...
@@ -31,7 +31,8 @@ namespace engine {
enum
class
ResourceType
{
DISK
=
0
,
CPU
=
1
,
GPU
=
2
GPU
=
2
,
TEST
=
3
,
};
class
Resource
:
public
Node
,
public
std
::
enable_shared_from_this
<
Resource
>
{
...
...
@@ -126,7 +127,6 @@ public:
bool
enable_loader
,
bool
enable_executor
);
// TODO: SearchContextPtr to TaskPtr
/*
* Implementation by inherit class;
* Blocking function;
...
...
@@ -142,11 +142,6 @@ public:
Process
(
TaskPtr
task
)
=
0
;
private:
/*
* These function should move to cost.h ???
* COST.H ???
*/
/*
* Pick one task to load;
* Order by start time;
...
...
cpp/src/scheduler/resource/TestResource.cpp
0 → 100644
浏览文件 @
e9174896
/*******************************************************************************
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#include "TestResource.h"
namespace
zilliz
{
namespace
milvus
{
namespace
engine
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
TestResource
&
resource
)
{
out
<<
resource
.
Dump
();
return
out
;
}
TestResource
::
TestResource
(
std
::
string
name
,
uint64_t
device_id
,
bool
enable_loader
,
bool
enable_executor
)
:
Resource
(
std
::
move
(
name
),
ResourceType
::
TEST
,
device_id
,
enable_loader
,
enable_executor
)
{
}
void
TestResource
::
LoadFile
(
TaskPtr
task
)
{
task
->
Load
(
LoadType
::
TEST
,
0
);
}
void
TestResource
::
Process
(
TaskPtr
task
)
{
task
->
Execute
();
}
}
}
}
cpp/src/scheduler/resource/TestResource.h
0 → 100644
浏览文件 @
e9174896
/*******************************************************************************
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#pragma once
#include "Resource.h"
namespace
zilliz
{
namespace
milvus
{
namespace
engine
{
class
TestResource
:
public
Resource
{
public:
explicit
TestResource
(
std
::
string
name
,
uint64_t
device_id
,
bool
enable_loader
,
bool
enable_executor
);
inline
std
::
string
Dump
()
const
override
{
return
"<TestResource, name="
+
name_
+
">"
;
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
TestResource
&
resource
);
protected:
void
LoadFile
(
TaskPtr
task
)
override
;
void
Process
(
TaskPtr
task
)
override
;
};
}
}
}
cpp/src/scheduler/task/Task.h
浏览文件 @
e9174896
...
...
@@ -22,6 +22,7 @@ enum class LoadType {
DISK2CPU
,
CPU2GPU
,
GPU2CPU
,
TEST
,
};
enum
class
TaskType
{
...
...
cpp/unittest/scheduler/resource_test.cpp
浏览文件 @
e9174896
...
...
@@ -8,6 +8,7 @@
#include "scheduler/resource/DiskResource.h"
#include "scheduler/resource/CpuResource.h"
#include "scheduler/resource/GpuResource.h"
#include "scheduler/resource/TestResource.h"
#include "scheduler/task/Task.h"
#include "scheduler/task/TestTask.h"
#include "scheduler/ResourceFactory.h"
...
...
@@ -18,7 +19,71 @@ namespace zilliz {
namespace
milvus
{
namespace
engine
{
class
ResourceTest
:
public
testing
::
Test
{
/************ ResourceBaseTest ************/
class
ResourceBaseTest
:
public
testing
::
Test
{
protected:
void
SetUp
()
override
{
only_loader_
=
std
::
make_shared
<
DiskResource
>
(
name1
,
id1
,
true
,
false
);
only_executor_
=
std
::
make_shared
<
CpuResource
>
(
name2
,
id2
,
false
,
true
);
both_enable_
=
std
::
make_shared
<
GpuResource
>
(
name3
,
id3
,
true
,
true
);
both_disable_
=
std
::
make_shared
<
TestResource
>
(
name4
,
id4
,
false
,
false
);
}
const
std
::
string
name1
=
"only_loader_"
;
const
std
::
string
name2
=
"only_executor_"
;
const
std
::
string
name3
=
"both_enable_"
;
const
std
::
string
name4
=
"both_disable_"
;
const
uint64_t
id1
=
1
;
const
uint64_t
id2
=
2
;
const
uint64_t
id3
=
3
;
const
uint64_t
id4
=
4
;
ResourcePtr
only_loader_
=
nullptr
;
ResourcePtr
only_executor_
=
nullptr
;
ResourcePtr
both_enable_
=
nullptr
;
ResourcePtr
both_disable_
=
nullptr
;
};
TEST_F
(
ResourceBaseTest
,
name
)
{
ASSERT_EQ
(
only_loader_
->
name
(),
name1
);
ASSERT_EQ
(
only_executor_
->
name
(),
name2
);
ASSERT_EQ
(
both_enable_
->
name
(),
name3
);
ASSERT_EQ
(
both_disable_
->
name
(),
name4
);
}
TEST_F
(
ResourceBaseTest
,
type
)
{
ASSERT_EQ
(
only_loader_
->
type
(),
ResourceType
::
DISK
);
ASSERT_EQ
(
only_executor_
->
type
(),
ResourceType
::
CPU
);
ASSERT_EQ
(
both_enable_
->
type
(),
ResourceType
::
GPU
);
ASSERT_EQ
(
both_disable_
->
type
(),
ResourceType
::
TEST
);
}
TEST_F
(
ResourceBaseTest
,
device_id
)
{
ASSERT_EQ
(
only_loader_
->
device_id
(),
id1
);
ASSERT_EQ
(
only_executor_
->
device_id
(),
id2
);
ASSERT_EQ
(
both_enable_
->
device_id
(),
id3
);
ASSERT_EQ
(
both_disable_
->
device_id
(),
id4
);
}
TEST_F
(
ResourceBaseTest
,
has_loader
)
{
ASSERT_TRUE
(
only_loader_
->
HasLoader
());
ASSERT_FALSE
(
only_executor_
->
HasLoader
());
ASSERT_TRUE
(
both_enable_
->
HasLoader
());
ASSERT_FALSE
(
both_disable_
->
HasLoader
());
}
TEST_F
(
ResourceBaseTest
,
has_executor
)
{
ASSERT_FALSE
(
only_loader_
->
HasExecutor
());
ASSERT_TRUE
(
only_executor_
->
HasExecutor
());
ASSERT_TRUE
(
both_enable_
->
HasExecutor
());
ASSERT_FALSE
(
both_disable_
->
HasExecutor
());
}
/************ ResourceAdvanceTest ************/
class
ResourceAdvanceTest
:
public
testing
::
Test
{
protected:
void
SetUp
()
override
{
...
...
@@ -31,14 +96,18 @@ protected:
auto
subscriber
=
[
&
](
EventPtr
event
)
{
if
(
event
->
Type
()
==
EventType
::
LOAD_COMPLETED
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
load_mutex_
);
++
load_count_
;
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
load_mutex_
);
++
load_count_
;
}
cv_
.
notify_one
();
}
if
(
event
->
Type
()
==
EventType
::
FINISH_TASK
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
load_mutex_
);
++
exec_count_
;
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
load_mutex_
);
++
exec_count_
;
}
cv_
.
notify_one
();
}
};
...
...
@@ -82,7 +151,32 @@ protected:
std
::
condition_variable
cv_
;
};
TEST_F
(
ResourceTest
,
cpu_resource_test
)
{
TEST_F
(
ResourceAdvanceTest
,
disk_resource_test
)
{
const
uint64_t
NUM
=
100
;
std
::
vector
<
std
::
shared_ptr
<
TestTask
>>
tasks
;
TableFileSchemaPtr
dummy
=
nullptr
;
for
(
uint64_t
i
=
0
;
i
<
NUM
;
++
i
)
{
auto
task
=
std
::
make_shared
<
TestTask
>
(
dummy
);
tasks
.
push_back
(
task
);
disk_resource_
->
task_table
().
Put
(
task
);
}
disk_resource_
->
WakeupLoader
();
WaitLoader
(
NUM
);
for
(
uint64_t
i
=
0
;
i
<
NUM
;
++
i
)
{
ASSERT_EQ
(
tasks
[
i
]
->
load_count_
,
0
);
}
disk_resource_
->
WakeupExecutor
();
WaitExecutor
(
NUM
);
for
(
uint64_t
i
=
0
;
i
<
NUM
;
++
i
)
{
ASSERT_EQ
(
tasks
[
i
]
->
exec_count_
,
0
);
}
}
TEST_F
(
ResourceAdvanceTest
,
cpu_resource_test
)
{
const
uint64_t
NUM
=
100
;
std
::
vector
<
std
::
shared_ptr
<
TestTask
>>
tasks
;
TableFileSchemaPtr
dummy
=
nullptr
;
...
...
@@ -94,8 +188,6 @@ TEST_F(ResourceTest, cpu_resource_test) {
cpu_resource_
->
WakeupLoader
();
WaitLoader
(
NUM
);
// std::cout << "after WakeupLoader" << std::endl;
// std::cout << cpu_resource_->task_table().Dump();
for
(
uint64_t
i
=
0
;
i
<
NUM
;
++
i
)
{
ASSERT_EQ
(
tasks
[
i
]
->
load_count_
,
1
);
...
...
@@ -103,15 +195,13 @@ TEST_F(ResourceTest, cpu_resource_test) {
cpu_resource_
->
WakeupExecutor
();
WaitExecutor
(
NUM
);
// std::cout << "after WakeupExecutor" << std::endl;
// std::cout << cpu_resource_->task_table().Dump();
for
(
uint64_t
i
=
0
;
i
<
NUM
;
++
i
)
{
ASSERT_EQ
(
tasks
[
i
]
->
exec_count_
,
1
);
}
}
TEST_F
(
ResourceTest
,
gpu_resource_test
)
{
TEST_F
(
Resource
Advance
Test
,
gpu_resource_test
)
{
const
uint64_t
NUM
=
100
;
std
::
vector
<
std
::
shared_ptr
<
TestTask
>>
tasks
;
TableFileSchemaPtr
dummy
=
nullptr
;
...
...
@@ -123,8 +213,6 @@ TEST_F(ResourceTest, gpu_resource_test) {
gpu_resource_
->
WakeupLoader
();
WaitLoader
(
NUM
);
// std::cout << "after WakeupLoader" << std::endl;
// std::cout << cpu_resource_->task_table().Dump();
for
(
uint64_t
i
=
0
;
i
<
NUM
;
++
i
)
{
ASSERT_EQ
(
tasks
[
i
]
->
load_count_
,
1
);
...
...
@@ -132,8 +220,6 @@ TEST_F(ResourceTest, gpu_resource_test) {
gpu_resource_
->
WakeupExecutor
();
WaitExecutor
(
NUM
);
// std::cout << "after WakeupExecutor" << std::endl;
// std::cout << cpu_resource_->task_table().Dump();
for
(
uint64_t
i
=
0
;
i
<
NUM
;
++
i
)
{
ASSERT_EQ
(
tasks
[
i
]
->
exec_count_
,
1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录