![MySql 与 Laravel Queue、Supervisor 和 FFMPEg 结合使用时停止运行](https://linux22.com/image/634930/MySql%20%E4%B8%8E%20Laravel%20Queue%E3%80%81Supervisor%20%E5%92%8C%20FFMPEg%20%E7%BB%93%E5%90%88%E4%BD%BF%E7%94%A8%E6%97%B6%E5%81%9C%E6%AD%A2%E8%BF%90%E8%A1%8C.png)
在设置队列侦听器以使用 FFMPEG 处理上传的视频后,我多次返回服务器,发现 MySql 已停止运行。我检查了驱动器空间,发现使用了约 77%(60G 中的 43G)。
这是我的代码,以防有用:
public function fire($job, $data)
{
$data = json_decode($data['transcoding_message'], true);
$output_directory = '/home/ubuntu/transcodes/';
$amazon_array = array();
$s3 = AWS::get('s3');
//execute main transcoding thread
$cmd = 'sudo ffmpeg -i ' . $data['temp_file_url'] . ' -y -vcodec libx264 -tune zerolatency -movflags faststart -crf 20 -profile:v main -level:v 3.1 -acodec libfdk_aac -b:a 256k ' . $output_directory. $data['temp_file_key'] . '_HQ.mp4 -vcodec libx264 -s ' . $sq_width . 'x' . $sq_height . ' -tune zerolatency -movflags faststart -crf 25 -profile:v main -level:v 3.1 -acodec libfdk_aac -b:a 256k ' . $output_directory. $data['temp_file_key'] . '_SQ.mp4 -ss ' . $seek_half . ' -f image2 -vf scale=iw/2:-1 -vframes 1 ' . $output_directory. $data['temp_file_key'] . '_thumb.jpg';
exec($cmd." 2>&1", $out, $ret);
if ($ret)
{
Log::error($cmd);
echo 'Processing error' . PHP_EOL;
//there was a problem
return;
}
else
{
//setup file urls
echo 'about to move files';
$hq_url = $this->bucket_root . $data['user_id'] . '/' . $data['temp_file_key'] . '_HQ.mp4';
$sq_url = $this->bucket_root . $data['user_id'] . '/' . $data['temp_file_key'] . '_SQ.mp4';;
$thumb_url = $this->bucket_root . $data['user_id'] . '/' . $data['temp_file_key'] . '_thumb.jpg';
$amazon_array['video_hq_url'] = $data['temp_file_key'] . '_HQ.mp4';
$amazon_array['video_sq_url'] = $data['temp_file_key'] . '_SQ.mp4';
$amazon_array['video_thumb_url'] = $data['temp_file_key'] . '_thumb.jpg';
//copy from temp to permanent
foreach ($amazon_array as $k => $f)
{
$uploader = UploadBuilder::newInstance()
->setClient($s3)
->setSource($output_directory.$f)
->setBucket($this->bucket)
->setKey('users/' . $data['user_id'] . '/' . $f)
->setConcurrency(10)
->setOption('ACL', 'public-read')
->build();
$uploader->getEventDispatcher()->addListener(
'multipart_upload.after_part_upload',
function($event) use ($f) {
// Do whatever you want
}
);
try {
$uploader->upload();
echo "{$k} => Upload complete.\n" . PHP_EOL;
DB::table('items')->where('id', $data['item_id'])->update(array($k => $this->bucket_root. $data['user_id'] . '/' .$f, 'deleted_at' => NULL));
//delete local
unlink($output_directory.$f);
unset($uploader);
} catch (MultipartUploadException $e) {
$uploader->abort();
echo "{$k} => Upload failed.\n" . PHP_EOL;
continue;
}
}
//write to database
DB::table('archives_items')->where('id', $data['archive_item_id'])->update(array('deleted_at' => NULL));
DB::connection('mysql3')->table('video_processing')->where('id', $data['id'])->update(array('finished_processing' => 1));
//delete files
//delete s3
$s3->deleteObject(
array(
'Bucket' => $this->temp_bucket,
'Key' => $data['file_name']
)
);
echo $data['temp_file_url'] . '=>' . " deleted from temp bucket.\n" . PHP_EOL;
DB::connection('mysql3')->table('video_processing')->where('id', $data['id'])->update(array('deleted_at' => \Carbon\Carbon::now()));
}
$job->delete();
// end of processing uploaded video
}
else
{
return;
}
关于 MySql 为何会这样死掉,有什么想法吗?
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
我想说的是,php artisanqueue:listen 命令是通过 Supervisor 触发的,并且我有 4 个正在运行的并发进程。
错误日志:
140613 5:37:52 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
140613 5:37:52 [Note] Plugin 'FEDERATED' is disabled.
140613 5:37:52 InnoDB: The InnoDB memory heap is disabled
140613 5:37:52 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140613 5:37:52 InnoDB: Compressed tables use zlib 1.2.3.4
140613 5:37:52 InnoDB: Initializing buffer pool, size = 128.0M
140613 5:37:52 InnoDB: Completed initialization of buffer pool
140613 5:37:52 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
140613 5:37:52 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
140613 5:37:53 InnoDB: Waiting for the background threads to start
140613 5:37:54 InnoDB: 5.5.37 started; log sequence number 2922980986
140613 5:37:54 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
140613 5:37:54 [Note] - '127.0.0.1' resolves to '127.0.0.1';
140613 5:37:54 [Note] Server socket created on IP: '127.0.0.1'.
140613 5:37:55 [Note] Event Scheduler: Loaded 0 events
140613 5:37:55 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.37-0ubuntu0.12.04.1' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu)
140613 5:38:10 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
140613 5:38:10 [Note] Plugin 'FEDERATED' is disabled.
140613 5:38:10 InnoDB: The InnoDB memory heap is disabled
140613 5:38:10 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140613 5:38:10 InnoDB: Compressed tables use zlib 1.2.3.4
140613 5:38:10 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
140613 5:38:10 InnoDB: Completed initialization of buffer pool
140613 5:38:10 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140613 5:38:10 [ERROR] Plugin 'InnoDB' init function returned error.
140613 5:38:10 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140613 5:38:10 [ERROR] Unknown/unsupported storage engine: InnoDB
140613 5:38:10 [ERROR] Aborting
140613 5:38:10 [Note] /usr/sbin/mysqld: Shutdown complete
答案1
InnoDB:mmap(137363456 字节)失败;错误号 12
140613 5:38:10 InnoDB:致命错误:无法为缓冲池分配内存
您的系统内存不足,错误 12 是内核发出 ENOMEM 信号。