Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
srvpro
Commits
5df13214
Commit
5df13214
authored
Sep 03, 2015
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix memory usage
parent
6e57e1f5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
26 deletions
+64
-26
room.coffee
room.coffee
+20
-1
room.js
room.js
+25
-3
ygopro-server.coffee
ygopro-server.coffee
+10
-11
ygopro-server.js
ygopro-server.js
+9
-11
No files found.
room.coffee
View file @
5df13214
...
...
@@ -2,12 +2,26 @@ _ = require 'underscore'
_
.
str
=
require
'underscore.string'
_
.
mixin
(
_
.
str
.
exports
());
spawn
=
require
(
'child_process'
).
spawn
spawnSync
=
require
(
'child_process'
).
spawnSync
ygopro
=
require
'./ygopro.js'
bunyan
=
require
'bunyan'
settings
=
require
'./config.json'
log
=
bunyan
.
createLogger
name
:
"mycard-room"
#获取可用内存
get_memory_usage
=
()
->
prc_free
=
spawnSync
(
"free"
,
[])
lines
=
prc_free
.
stdout
.
toString
().
split
(
/\n/g
)
line
=
lines
[
1
].
split
(
/\s+/
)
total
=
parseInt
(
line
[
1
],
10
)
free
=
parseInt
(
line
[
3
],
10
)
buffers
=
parseInt
(
line
[
5
],
10
)
cached
=
parseInt
(
line
[
6
],
10
)
actualFree
=
free
+
buffers
+
cached
percentUsed
=
parseFloat
(((
1
-
(
actualFree
/
total
))
*
100
).
toFixed
(
2
))
return
percentUsed
class
Room
#name
#port
...
...
@@ -19,7 +33,12 @@ class Room
@
all
=
[]
@
find_or_create_by_name
:
(
name
)
->
@
find_by_name
(
name
)
?
new
Room
(
name
)
if
room
=
@
find_by_name
(
name
)
return
room
else
if
get_memory_usage
()
>=
90
return
null
else
return
new
Room
(
name
)
@
find_by_name
:
(
name
)
->
result
=
_
.
find
@
all
,
(
room
)
->
...
...
room.js
View file @
5df13214
// Generated by CoffeeScript 1.9.3
(
function
()
{
var
Room
,
_
,
bunyan
,
log
,
settings
,
spawn
,
ygopro
;
var
Room
,
_
,
bunyan
,
get_memory_usage
,
log
,
settings
,
spawn
,
spawnSync
,
ygopro
;
_
=
require
(
'
underscore
'
);
...
...
@@ -10,6 +10,8 @@
spawn
=
require
(
'
child_process
'
).
spawn
;
spawnSync
=
require
(
'
child_process
'
).
spawnSync
;
ygopro
=
require
(
'
./ygopro.js
'
);
bunyan
=
require
(
'
bunyan
'
);
...
...
@@ -20,12 +22,32 @@
name
:
"
mycard-room
"
});
get_memory_usage
=
function
()
{
var
actualFree
,
buffers
,
cached
,
free
,
line
,
lines
,
percentUsed
,
prc_free
,
total
;
prc_free
=
spawnSync
(
"
free
"
,
[]);
lines
=
prc_free
.
stdout
.
toString
().
split
(
/
\n
/g
);
line
=
lines
[
1
].
split
(
/
\s
+/
);
total
=
parseInt
(
line
[
1
],
10
);
free
=
parseInt
(
line
[
3
],
10
);
buffers
=
parseInt
(
line
[
5
],
10
);
cached
=
parseInt
(
line
[
6
],
10
);
actualFree
=
free
+
buffers
+
cached
;
percentUsed
=
parseFloat
(((
1
-
(
actualFree
/
total
))
*
100
).
toFixed
(
2
));
return
percentUsed
;
};
Room
=
(
function
()
{
Room
.
all
=
[];
Room
.
find_or_create_by_name
=
function
(
name
)
{
var
ref
;
return
(
ref
=
this
.
find_by_name
(
name
))
!=
null
?
ref
:
new
Room
(
name
);
var
room
;
if
(
room
=
this
.
find_by_name
(
name
))
{
return
room
;
}
else
if
(
get_memory_usage
()
>=
90
)
{
return
null
;
}
else
{
return
new
Room
(
name
);
}
};
Room
.
find_by_name
=
function
(
name
)
{
...
...
ygopro-server.coffee
View file @
5df13214
...
...
@@ -16,7 +16,7 @@ request = require 'request'
bunyan
=
require
'bunyan'
heapdump
=
require
'heapdump'
#
heapdump = require 'heapdump'
#配置文件
settings
=
require
'./config.json'
...
...
@@ -221,15 +221,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
code
:
2
}
client
.
end
()
else
if
(
os
.
freemem
()
/
os
.
totalmem
())
<=
0.1
ygopro
.
stoc_send_chat
(
client
,
"服务器已经爆满,请稍候再试"
)
ygopro
.
stoc_send
client
,
'ERROR_MSG'
,{
msg
:
1
code
:
2
}
client
.
end
()
else
if
!
Room
.
validate
(
info
.
pass
)
#ygopro.stoc_send client, 'ERROR_MSG',{
# msg: 1
...
...
@@ -252,7 +244,14 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else
#log.info 'join_game',info.pass, client.name
client
.
room
=
Room
.
find_or_create_by_name
(
info
.
pass
)
if
client
.
room
.
started
if
!
client
.
room
ygopro
.
stoc_send_chat
(
client
,
"服务器已经爆满,请稍候再试"
)
ygopro
.
stoc_send
client
,
'ERROR_MSG'
,{
msg
:
1
code
:
2
}
client
.
end
()
else
if
client
.
room
.
started
if
settings
.
modules
.
post_start_watching
client
.
is_post_watcher
=
true
ygopro
.
stoc_send_chat_to_room
client
.
room
,
"
#{
client
.
name
}
加入了观战"
...
...
ygopro-server.js
View file @
5df13214
// Generated by CoffeeScript 1.9.3
(
function
()
{
var
Room
,
_
,
bunyan
,
debug
,
dialogues
,
execFile
,
fs
,
h
eapdump
,
h
ttp
,
http_server
,
log
,
net
,
os
,
path
,
request
,
settings
,
tips
,
url
,
ygopro
;
var
Room
,
_
,
bunyan
,
debug
,
dialogues
,
execFile
,
fs
,
http
,
http_server
,
log
,
net
,
os
,
path
,
request
,
settings
,
tips
,
url
,
ygopro
;
net
=
require
(
'
net
'
);
...
...
@@ -26,8 +26,6 @@
bunyan
=
require
(
'
bunyan
'
);
heapdump
=
require
(
'
heapdump
'
);
settings
=
require
(
'
./config.json
'
);
ygopro
=
require
(
'
./ygopro.js
'
);
...
...
@@ -231,13 +229,6 @@
code
:
2
});
client
.
end
();
}
else
if
((
os
.
freemem
()
/
os
.
totalmem
())
<=
0.1
)
{
ygopro
.
stoc_send_chat
(
client
,
"
服务器已经爆满,请稍候再试
"
);
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
msg
:
1
,
code
:
2
});
client
.
end
();
}
else
if
(
!
Room
.
validate
(
info
.
pass
))
{
ygopro
.
stoc_send_chat
(
client
,
"
房间密码不正确
"
);
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
...
...
@@ -253,7 +244,14 @@
client
.
end
();
}
else
{
client
.
room
=
Room
.
find_or_create_by_name
(
info
.
pass
);
if
(
client
.
room
.
started
)
{
if
(
!
client
.
room
)
{
ygopro
.
stoc_send_chat
(
client
,
"
服务器已经爆满,请稍候再试
"
);
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
msg
:
1
,
code
:
2
});
client
.
end
();
}
else
if
(
client
.
room
.
started
)
{
if
(
settings
.
modules
.
post_start_watching
)
{
client
.
is_post_watcher
=
true
;
ygopro
.
stoc_send_chat_to_room
(
client
.
room
,
client
.
name
+
"
加入了观战
"
);
...
...
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