2016-07-24 2 views
-1

우리는 아마존 EC2 인스턴스가 실행 중이고 EC2 인스턴스에 이미 웹 애플리케이션을 배치했으며 애플리케이션은 Laravel 5.0 프레임 워크에서 개발되었습니다. 우리는 AWS RDS 인스턴스를 가지고 우리의 테이블 구조는 다음과 같습니다 무엇 우리가하고있는 문제와 필요한 몇 가지 제안/same.Basically의 입력 : 내가 더 (6 개) 테이블이AWS EC2 PHP, Laravel, MySQL 성능

CREATE TABLE IF NOT EXISTS `adwords_data` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 
    `client_id` bigint(20) NOT NULL, 
    `date_preset` enum('YESTERDAY','LAST_7_DAYS','LAST_14_DAYS','LAST_30_DAYS','ALL_TIME','7_DAYS_PRIOR_YESTERDAY','30_DAYS_PRIOR_YESTERDAY','60_DAYS_PRIOR_YESTERDAY','90_DAYS_PRIOR_YESTERDAY') COLLATE utf8_unicode_ci NOT NULL, 
    `CampaignId` bigint(20) NOT NULL, 
    `CampaignName` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
    `AdgroupId` bigint(20) NOT NULL, 
    `AdgroupName` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
    `Clicks` int(11) NOT NULL, 
    `Impressions` int(11) NOT NULL, 
    `ConvertedClicks` int(11) NOT NULL, 
    `Conversions` int(11) NOT NULL, 
    `Cost` decimal(10,2) NOT NULL, 
    `AveragePosition` decimal(10,2) NOT NULL, 
    `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', 
    `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', 
    PRIMARY KEY (`id`), 
    KEY `adwords_data_client_id_index` (`client_id`), 
    KEY `adwords_data_date_preset_index` (`date_preset`), 
    KEY `adwords_data_campaignid_index` (`CampaignId`), 
    KEY `adwords_data_adgroupid_index` (`AdgroupId`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 

위처럼하지만 필드는 조금 다른

여기에 my.cnf가 표시됩니다.

# 
# The MySQL database server configuration file. 
# 
# You can copy this to one of: 
# - "/etc/mysql/my.cnf" to set global options, 
# - "~/.my.cnf" to set user-specific options. 
# 
# One can use all long options that the program supports. 
# Run program with --help to get a list of available options and with 
# --print-defaults to see which it would actually understand and use. 
# 
# For explanations see 
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html 

# This will be passed to all mysql clients 
# It has been reported that passwords should be enclosed with ticks/quotes 
# escpecially if they contain "#" chars... 
# Remember to edit /etc/mysql/debian.cnf when changing the socket location. 
[client] 
loose-local-infile = 1 
port  = 3306 
socket  = /var/run/mysqld/mysqld.sock 

# Here is entries for some specific programs 
# The following values assume you have at least 32M ram 

# This was formally known as [safe_mysqld]. Both versions are currently parsed. 
[mysqld_safe] 
socket  = /var/run/mysqld/mysqld.sock 
nice  = 0 

[mysqld] 
# 
# * Basic Settings 
# 
local-infile = 1 
user  = mysql 
pid-file = /var/run/mysqld/mysqld.pid 
socket  = /var/run/mysqld/mysqld.sock 
port  = 3306 
basedir  = /usr 
datadir  = /var/lib/mysql 
tmpdir  = /tmp 
lc-messages-dir = /usr/share/mysql 
lower_case_table_names=1 
table_open_cache=512 
query_alloc_block_size=16384 
thread_concurrency=8 
join_buffer_size=2M 
read_buffer_size=4M 
tmp_table_size=1024M 
max_heap_table_size=1024M # added 
innodb_lock_wait_timeout=50 
#table_cache=4960 
query_cache_size=99M # changed from 1024 
query_cache_type=ON # added 
myisam_sort_buffer_size=64M 
symbolic-links=0 
thread_cache_size=16 
read_rnd_buffer_size=32M 
query_prealloc_size=16384 
key_buffer_size=1024M 
sort_buffer_size=2M 
tmpdir="/tmp" 
ft_min_word_len=3 
default-storage-engine=MyISAM 
innodb_file_per_table=1 
innodb_flush_log_at_trx_commit=2 
max_allowed_packet=16M 
open_files_limit=49996 
user   = mysql 


skip-external-locking 
# 
# Instead of skip-networking the default is now to listen only on 
# localhost which is more compatible and is not less secure. 
bind-address  = 127.0.0.1 
# 
# * Fine Tuning 
# 
key_buffer  = 16M 
max_allowed_packet = 16M 
thread_stack  = 192K 
thread_cache_size  = 8 
# This replaces the startup script and checks MyISAM tables if needed 
# the first time they are touched 
myisam-recover   = BACKUP 
max_connections  = 3000 
#table_cache   = 64 
#thread_concurrency  = 10 
# 
# * Query Cache Configuration 
# 
query_cache_limit = 1M 
query_cache_size  = 16M 
# 
# * Logging and Replication 
# 
# Both location gets rotated by the cronjob. 
# Be aware that this log type is a performance killer. 
# As of 5.1 you can enable the log at runtime! 
#general_log_file  = /var/log/mysql/mysql.log 
#general_log    = 1 
# 
# Error log - should be very few entries. 
# 
log_error = /var/log/mysql/error.log 
# 
# Here you can see queries with especially long duration 
#log_slow_queries = /var/log/mysql/mysql-slow.log 
#long_query_time = 2 
#log-queries-not-using-indexes 
# 
# The following can be used as easy to replay backup logs or for replication. 
# note: if you are setting up a replication slave, see README.Debian about 
#  other settings you may need to change. 
#server-id  = 1 
#log_bin   = /var/log/mysql/mysql-bin.log 
expire_logs_days = 10 
max_binlog_size   = 100M 
#binlog_do_db  = include_database_name 
#binlog_ignore_db = include_database_name 
# 
# * InnoDB 
# 
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. 
# Read the manual for more InnoDB related options. There are many! 
# 
# * Security Features 
# 
# Read the manual, too, if you want chroot! 
# chroot = /var/lib/mysql/ 
# 
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". 
# 
# ssl-ca=/etc/mysql/cacert.pem 
# ssl-cert=/etc/mysql/server-cert.pem 
# ssl-key=/etc/mysql/server-key.pem 



[mysqldump] 
quick 
quote-names 
max_allowed_packet = 16M 

[mysql] 
local-infile = 1 
#no-auto-rehash # faster start of mysql but no tab completition 

[isamchk] 
key_buffer  = 16M 

# 
# * IMPORTANT: Additional settings that can override those from this file! 
# The files must end with '.cnf', otherwise they'll be ignored. 
# 
!includedir /etc/mysql/conf.d/ 

우리의 응용 프로그램은 다른 기간에 대해 Google 애드워즈 API를 호출하고 반환 된 데이터를 CSV 파일에 저장합니다.이 CSV 파일을 처리하고 데이터를 mysql 데이터베이스 테이블 (약 200,000 개의 레코드)에 저장 한 다음 처리해야합니다 이 200,000 레코드, 우리는 각각의 200 K 레코드를 스캔 한 다음 비즈니스 논리를 적용해야합니다 (즉, 내부 논리는 Sum, Avg 등과 같은 일부 MySQL 집계를 적용한다는 것을 의미합니다). 그러나이 200K 레코드를 처리하는 데는 2 시간 정도가 걸리지 만 이 처리 시간을 줄여야합니다. 다음은

우리가 반복 테이블 adwords_data에서 프로세스를 completeting 후 우리가 배치

https://laravel.com/docs/5.0/eloquent

\DB::table('adwords_data')->select('CampaignId', 'AdgroupId')->where('client_id', '=', $client_id)->groupBy('CampaignId', 'AdgroupId')->chunk('500', function ($adwords_data) { 
       foreach($adwords_data as $data){ 
        // process each AdgroupId by checking the summation of conversion stats and apply conditions 
       } 
} 

에서 데이터를 처리하는 Laravel 청크 방법을 사용하고이 200K Records.We을 처리하기 위해 사용하는 코드베이스입니다 다른 6 개의 테이블과 같은 프로세스. 그러나 성능이 좋지 않아 실행 속도가 빨라집니다.

누구나 성능을 향상시킬 수있는 가장 좋은 방법을 제안 해 줄 수 있습니까?

감사합니다.

+1

귀하의 질문은 누구에게나 훌륭한 조언을 제공 할만큼 충분하지 않습니다. 나는 MySQL의 전문가는 아니지만 나에게 테이블 정의는 괜찮아 보인다 - 로켓 과학 - 잠재적 인 문제는 1) MySQL config ("my.cnf")는 optimium으로 구성되지 않았다. 2) 처리 코드가 잘못 작성되었다. 3) AWS nano를 사용하는 경우 더 큰 기계가 필요할 수도 있습니다. my.cnf 파일과 코드를 제공하면 기회가 합리적으로 도움이 될 수 있습니다. 행운을 빕니다 –

+0

@fiprojects 물론 제공 할 수 있습니다! 나에게 이메일 주소를 알려주시겠습니까? 자세한 내용은 이메일을 통해 설명 드리겠습니다 –

+0

더 자세한 정보는 없습니까? 내 이메일 주소는 –

답변

0

Ronak - 여러분은 민속이 위의 설명에 지나치게 가혹하다고 생각할 수도 있지만 여러 문제에 대한 답변을 찾고 있습니다 (문제가 무엇인지 명확하지 않습니다). 민중은 느슨한 나사 몇 개를 조일 때 도움이되지만 무거운 물건을 들지는 않습니다. 자신의 기술을 개발하거나 한 명 또는 그 이상의 사람들에게 유급 도움을 받으면서 책임을 수행해야합니다.

귀하의 프로젝트에 대한 정보와 배경이 부족하기 때문에 최고의 의도를 가진 사람들은 당신을 돕기 위해 빨대에서 당길 것입니다.

당신이 가진 문제는 문제의 원인을 파악하기 위해 어떤 포럼에서든지 하나의 Q & A를 뛰어 넘는 기술을 필요로합니다. 그 다음에 Q & A가 솔루션을 구현합니다.

이 포럼은 특정 작업과 관련된 기술적 인 질문에 대한 답변을 제공합니다. 가장 기본적인 용어로 stackoverflow는 자동차의 휠을 변경하는 데 도움이되지만 자동차를 설계하지는 않습니다.

자신에게 물어보십시오 ... 성능 문제는 어디에서 발생할 수 있습니까? 성능 문제는 디스크, 네트워크, CPU, 메모리 또는 위의 모든 것일 수 있습니다. 당신이 예상했던 것보다 시간이 오래 걸리므로 문제를 해결할 필요가 있음을 의미합니다 ... "분열하고 정복하십시오".

컴퓨터에서 실행중인 프로그램이 있습니까? 어떤 크기의 기계입니까?

db 구성을 벤치 테스트했거나 기본 구성을 선택했는데 어떤 것을 던지겠습니까?

그것은 당신이 생략 로 요약 한 코드의 많은 부분에 문제 "전환 통계의 요약을 확인하여 프로세스를 각각의 adGroupId입니다 및 조건을 적용"당신은 당신의 코드 내에서 많은 양의 데이터를 씹는 할 수을 수 있으며, 메모리 나 CPU의 사용 빈도를 줄이거 나 기대치에 부합하지 않는 완벽한 데이터베이스로 완벽한 코드를 만들 수 있습니다.

분할 및 정복 - for/while 루프 외부에서 처리되는 기간을 측정하고, 데이터베이스에 대한 읽기/쓰기 지속 시간을 측정하고, 가장 오래 걸리는 것을 검사합니다.

행운을 빕니다