Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Ravada-Mirror
Commits
628875e9
Commit
628875e9
authored
Apr 11, 2017
by
Francesc Guasch
Browse files
[#176] download requests are huge
Manage huge requests, only 1 at a time
parent
4e40925b
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/Ravada.pm
View file @
628875e9
...
...
@@ -42,12 +42,19 @@ our $CONFIG = {};
our
$DEBUG
;
our
$CAN_FORK
=
1
;
our
$CAN_LXC
=
0
;
# Seconds to wait for other long process
our
$SECONDS_WAIT_CHILDREN
=
2
;
# Limit for long processes
our
$LIMIT_PROCESS
=
2
;
our
$LIMIT_HUGE_PROCESS
=
1
;
our
$DIR_SQL
=
"
sql/mysql
";
$DIR_SQL
=
"
/usr/share/doc/ravada/sql/mysql
"
if
!
-
e
$DIR_SQL
;
# LONG commands take long
our
%LONG_COMMAND
=
map
{
$_
=>
1
}
qw(prepare_base remove_base screenshot)
;
our
%HUGE_COMMAND
=
map
{
$_
=>
1
}
qw(download)
;
our
%LONG_COMMAND
=
map
{
$_
=>
1
}
(
qw(prepare_base remove_base screenshot )
,
keys
%HUGE_COMMAND
);
has
'
vm
'
=>
(
is
=>
'
ro
'
...
...
@@ -166,6 +173,7 @@ sub _upgrade_tables {
$self
->
_upgrade_table
('
requests
','
at_time
','
int(11) DEFAULT NULL
');
$self
->
_upgrade_table
('
iso_images
','
md5_url
','
varchar(255)
');
$self
->
_upgrade_table
('
iso_images
','
file_re
','
char(64)
');
$self
->
_upgrade_table
('
iso_images
','
device
','
varchar(255)
');
}
...
...
@@ -835,8 +843,11 @@ sub _execute {
$request
->
status
('
working
');
my
$pid
=
fork
();
die
"
I can't fork
"
if
!
defined
$pid
;
$self
->
_do_execute_command
(
$sub
,
$request
)
if
$pid
==
0
;
$self
->
_add_pid
(
$pid
,
$request
->
id
);
if
(
$pid
==
0
)
{
$self
->
_do_execute_command
(
$sub
,
$request
)
}
else
{
$self
->
_add_pid
(
$pid
,
$request
->
id
);
}
# $self->_connect_vm_kvm();
return
'';
}
...
...
@@ -926,13 +937,25 @@ sub _wait_children {
my
$req
=
shift
or
confess
"
Missing request
";
my
$try
=
0
;
for
(
1
..
10
)
{
for
(
1
..
$SECONDS_WAIT_CHILDREN
)
{
my
$n_pids
=
scalar
keys
%
{
$self
->
{
pids
}};
my
$msg
=
$req
->
id
.
"
"
.
$req
->
command
.
"
waiting for processes to finish
$n_pids
of
$LIMIT_PROCESS
running
";
warn
$msg
if
$DEBUG
;
return
if
$n_pids
<
$LIMIT_PROCESS
;
my
$msg
;
if
(
$HUGE_COMMAND
{
$req
->
command
})
{
if
(
$n_pids
<
$LIMIT_HUGE_PROCESS
)
{
$msg
=
$req
->
id
.
"
"
.
$req
->
command
.
"
waiting for processes to finish
$n_pids
"
.
"
of
$LIMIT_HUGE_PROCESS
";
warn
$msg
if
$DEBUG
;
return
;
}
}
elsif
(
$n_pids
<
$LIMIT_PROCESS
)
{
$msg
=
$req
->
id
.
"
"
.
$req
->
command
.
"
waiting for processes to finish
$n_pids
"
.
"
of
$LIMIT_PROCESS
";
warn
$msg
if
$DEBUG
;
return
;
}
$self
->
_wait_pids_nohang
();
sleep
1
;
...
...
@@ -952,7 +975,7 @@ sub _wait_pids_nohang {
my
$kid
=
waitpid
(
$pid
,
WNOHANG
);
next
if
!
$kid
||
$kid
==
-
1
;
$self
->
_set_req_done
(
$kid
);
delete
$self
->
{
pids
}
->
{
$kid
}
;
$self
->
_delete_pid
(
$kid
)
;
}
}
...
...
@@ -984,7 +1007,7 @@ sub _wait_pids {
# warn "Found $kid";
$self
->
_set_req_done
(
$pid
);
delete
$self
->
{
pids
}
->
{
$kid
}
;
$self
->
_delete_pid
(
$kid
)
;
return
if
$kid
==
$pid
;
}
}
...
...
@@ -995,6 +1018,14 @@ sub _add_pid {
my
$id_req
=
shift
;
$self
->
{
pids
}
->
{
$pid
}
=
$id_req
;
}
sub
_delete_pid
{
my
$self
=
shift
;
my
$pid
=
shift
;
delete
$self
->
{
pids
}
->
{
$pid
};
}
sub
_cmd_remove
{
...
...
@@ -1141,10 +1172,15 @@ sub _cmd_download {
my
$self
=
shift
;
my
$request
=
shift
;
my
$id_iso
=
$request
->
args
('
uid
')
or
confess
"
Missing argument uid
";
my
$id_iso
=
$request
->
args
('
id_iso
')
or
confess
"
Missing argument id_iso
";
my
$delay
=
$request
->
defined_arg
('
delay
');
sleep
$delay
if
$delay
;
# Ravada::KVM_search_iso
# my $iso = $self-_search_iso($id_iso);
}
sub
_cmd_shutdown
{
...
...
@@ -1245,6 +1281,7 @@ sub _req_method {
,
create
=>
\
&_cmd_create
,
remove
=>
\
&_cmd_remove
,
resume
=>
\
&_cmd_resume
,
download
=>
\
&_cmd_download
,
shutdown
=>
\
&_cmd_shutdown
,
hybernate
=>
\
&_cmd_hybernate
,
set_driver
=>
\
&_cmd_set_driver
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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