2016-07-24 14 views
-1

私たちはamazon EC2インスタンスを起動しており、すでにec2インスタンスにWebアプリケーションをデプロイしており、アプリケーションはLaravel 5.0フレームワークで開発されています。しかし、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 ; 

私はより多くの6つのテーブルが、フィールドは

少し異なっている必要があり、上記のように:私たちはAWS RDSインスタンスを持っていると私たちのテーブル構造は以下の通りである私たちがやっていることsame.Basicallyのためにいくつかの提案/入力を発行している必要があります

ここでは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 Adwords APIを呼び出し、返されたデータをCSVファイルに保存します。このCSVファイルを処理し、データをmysqlデータベーステーブル(約200,000レコード)に保存してから処理しますこの200,000レコードを200Kレコードごとにスキャンし、ビジネスロジックを適用する必要があります(つまり、内部ロジックはSum、AvgなどのいくつかのMySQL集約を適用することを意味します)。しかし、200Kレコードの処理には2時間ほどかかりますが、この処理時間を短縮する必要があります。以下は

我々はこれらの200K Records.Weを処理するために使用しているコードベースは、私たちは繰り返しバッチでデータを処理するために、テーブル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チャンクの方法を使用しているあります上記の他の6つのテーブルと同じプロセスです。しかし、パフォーマンスは、実行をより速くするために必要なほど良くはありません。

誰でも私たちにパフォーマンスを向上させる最善の方法を提案できますか?

ありがとうございます!

+1

あなたの質問には、誰でも良いアドバイスを提供するのに十分な詳細がありません。私はMySQLの専門家ではありませんが、私のテーブル定義はロケット科学ではないようです。潜在的な問題は1)MySQLの設定( "my.cnf")は設定されていません2)あなたの処理コードはあまり書かれていません。 AWS nanoを使用している場合は、より大きなマシンが必要になるかもしれません。 my.cnfファイルとコードを提供することをお勧めします。そうすれば、合理的な助けとなるでしょう。運が良ければ –

+0

@fiprojects確かに私はそれを提供することができます!あなたは私にあなたの電子メールIDを共有できますか?詳細をメールで説明します –

+0

答えに必要な情報はありませんか?私の電子メールは私のプロフィールです –

答えて

0

Ronak - あなたはフォークが上記のコメントで過度に厳しいと思うかもしれませんが、あなたは複数の問題(これらの問題が何であるかはっきりしていません)に対する答えを求めています。フォークは、いくつかの緩いネジを締めるのに役立ちますが、重い持ち上げをするつもりはありません。あなた自身のスキルを開発するか、または1人または複数の人々から報酬を得ることによって、あなた自身が何らかの責任を負う必要があります。

あなたのプロジェクトのインフォメーションとバックグラウンドが不足しているため、最善の意図を持っている人たちは、あなたを助けようと努力しています。

問題は、問題の原因を特定するために最初にフォーラム内で単一のQ & Aを超えて多くのスキルを必要とします。次に、より多くのQ & Aがソリューションを実装します。

このフォーラムは、特定のタスクに関連する技術的な質問に答えるのに役立ちます。基本的には、stackoverflowは車のホイールを変更するのに役立ちますが、あなたの車をデザインすることはありません。

自分自身に尋ねる...あなたはパフォーマンス上の問題がどこにありますか?パフォーマンスの問題は、ディスク、ネットワーク、CPU、メモリ、または上記のすべてになります。あなたが予想以上に時間がかかっているというだけで、問題を解決する必要があることを意味します...「分裂して征服する」。

マシンには何か他のものがありますか?マシンのサイズはどれくらいですか?

DB構成をベンチテストしたのですか、すぐに使用することを考えずにすぐに構成を選択しましたか?

それはあなたが省略され、のようにまとめているコードの大部分の問題として「コンバージョン統計情報の合計を確認することで、各ADGROUPIDをプロセスと条件を適用する」ことができあなたはあなたのコードの中に大量のデータを噛むことができ、おそらくメモリやCPUの貧弱な使い方をするか、期待に合わないマシン上で完璧なデータベースを使って完璧なコードを作ることができます。

for/whileループの処理時間を測定し、データベースへの読み込み/書き込みの持続時間を測定し、最長のものを調べます。

運が良ければ

関連する問題