node aws 內存溢出_在AWS Elastic Beanstalk上運行生產Node應用程序的現實

node aws 內存溢出

by Jared Nutt

賈里德·努特(Jared Nutt)

在AWS Elastic Beanstalk上運行生產Node應用程序的現實 (The reality of running a production Node app on AWS Elastic Beanstalk)

從在AWS的ELB平臺上運行生產Node應用程序兩年的經驗教訓 (Lessons learned from 2 years of running a production Node app on AWS’ ELB platform)

前題 (Front-Matter)

Let’s be honest, the AWS pricing calculator is confusing. Part of that is because of the a la carte method of payments AWS offers. This makes trying to give a good quote to a client difficult. Hopefully this article can provide some light on how much it costs to run an app, as well as some ways to reduce cost.

坦白地說, AWS定價計算器令人困惑。 部分原因是因為AWS提供了點菜付款方式。 這使得試圖給客戶良好的報價變得困難。 希望本文能夠提供一些有關運行應用程序的成本的信息,以及一些降低成本的方法。

運行應用程序的實際成本 (The Real Cost of Running an App)

I’ve been managing a node web-app on ELB for about two years now. The first year was great, they gave you everything for free (mostly)! After that, you have to start paying for stuff, like EC2 instances.

我已經在ELB上管理節點Web應用程序大約兩年了。 第一年很棒,他們免費為您提供了一切(主要是)! 之后,您必須開始支付費用,例如EC2實例。

This article will focus on my specific app requirements, which is a node based express app that is hosted on Elastic Beanstalk.

本文將重點介紹我的特定應用程序需求,這是托管在Elastic Beanstalk上的基于節點的快速應用程序。

For full details about the build, see my previous article here.

有關構建完整的詳細信息,請參閱我以前的文章在這里 。

分解 (Breakdown)

This is what I’m currently running on AWS:

這是我當前在AWS上運行的內容:

Single EBS Environment (U.S. West Region):

單一EBS環境(美國西部地區):

  • 1 Classic Load Balancer

    1個經典負載均衡器
  • 1 t2.micro EC2 instance

    1個t2.micro EC2實例
  • S3 Bucket that holds images (7 GB at time of writing)

    S3存儲圖像的存儲桶(寫入時為7 GB)
  • 1 Route 53 Hosted Zone

    1 Route 53托管區

$18 (Load Balancer) + $5 (EC2 with an RI) + $0.50 (Route 53) + $0.17 (S3) + $0.21 (Data Transfer) = Roughly $25 a month.

$ 18 (負載均衡器)+ $ 5 (帶RI的EC2)+ $ 0.50 (Route 53)+ $ 0.17 (S3)+ $ 0.21 (數據傳輸)=每月大約$ 25

Additionally, I host a MongoDB elsewhere, so if you plan on hosting a DB on AWS, that will incur additional costs. Let’s break down the various costs.

此外,我在其他地方托管MongoDB,因此,如果您計劃在AWS上托管數據庫,則會產生額外的費用。 讓我們分解各種費用。

負載均衡器 (Load Balancer)

This is the most expensive part of the stack. It costs:

這是堆棧中最昂貴的部分。 它的成本:

  • $0.025 per Classic Load Balancer-hour (or partial hour)

    每個經典負載均衡器小時(或不足一小時)0.025 USD
  • $0.008 per GB of data processed by a Classic Load Balancer

    Classic Load Balancer處理的每GB數據$ 0.008

That means, if you run your app 24 hours a day, it will cost roughly $18 + data charges, every month.

這意味著,如果您一天24小時運行您的應用,則每月將花費大約18美元+數據費用。

EC2實例 (EC2 Instance)

On-Demand EC2 instances are more expensive than they should be. To save some money here, refer to the section below about Reserved EC2 Instances. In case you were wondering, it would cost $8.40 to run the same type of EC2 instance as mentioned above, on-demand.

按需EC2實例比其應有的價格昂貴。 要在此處節省一些資金,請參閱以下有關預留的EC2實例的部分。 如果您想知道,按需運行上述類型的EC2實例將花費$ 8.40。

S3 (S3)

I have a couple S3 buckets. One for my static home page, one for holding images and one for holding the application version. As far as I know, ELB automatically creates the one for managing the application versions.

我有幾個S3水桶。 一個用于我的靜態主頁,一個用于保存圖像,一個用于保存應用程序版本。 據我所知,ELB自動創建一個用于管理應用程序版本的版本。

The S3 is pretty cheap, so I’m not too worried about trying to nickel and dime it, but there are ways to save money via their Glacier system.

S3相當便宜,所以我不太擔心嘗試鍍鎳和變角,但是有很多方法可以通過其Glacier系統省錢。

數據庫 (Database)

I host my MongoDB DB at mLab, which is going away soon. So I’ll update this when I sort out how much that is actually gonna cost once I’m forced to move over to Mongo’s Atlas.

我將我的MongoDB數據庫托管在mLab上,該數據庫即將消失。 因此,當我確定我被迫轉到Mongo的地圖集后實際要花費多少時,我將對其進行更新。

預留的EC2實例 (Reserved EC2 Instances)

Let’s talk about Reserved Instances (RI). Amazon’s convoluted billing system is the most confusing part about managing anything on AWS. Reserved Instances can alleviate some of the cost, but are way too confusing.

讓我們談談保留實例(RI)。 亞馬遜繁雜的賬單系統是有關在AWS上管理任何內容的最令人困惑的部分。 預留實例可以減輕一些開銷,但是太令人困惑了。

After a lot of reading and talking with the AWS customer service, this is what I sorta figured out.

經過大量的閱讀和與AWS客戶服務的交談之后,我才想到了這一點。

First, there are two different ways you can reserve where the RI is: Regional and Availability Zone. Regional means, it is specific to one of the main regions, eg. us-west-2 (Oregon). The availability zone (AZ) is specific to a zone within that region, e.g. us-west-2a (Oregon).

首先,您可以通過兩種不同的方式來保留RI的位置:區域和可用區。 地區性手段,它特定于主要地區之一,例如。 us-west-2(俄勒岡州)。 可用性區(AZ)是特定的某個區域,區域內,例如,美國西-2(俄勒岡州)。

I bought an RI within us-west-2 and it was automatically applied to my instance running in that area. If you buy one within the AZ, it will only apply to the specific AZ, e.g. us-west-2a, so if ELB spins up an EC2 instance in us-west2b, you’re out of luck.

我在us-west-2內購買了一個RI,它已自動應用于在該區域運行的實例。 如果您在AZ中購買一個,它將僅適用于特定的AZ,例如us-west-2a,因此,如果ELB在us-west2b中啟動EC2實例,您將不走運。

Additionally, there are “standard” and “convertible” types of RIs. I’m not 100% on what that means, but from what I understand convertible is more flexible on what you can swap it to, but more expensive.

此外,還有“標準”和“可轉換”類型的RI。 我不是100%的意思,但據我了解,敞篷車在您可以換用的東西上更靈活,但價格更高。

Finally, there are three types of payment types: No Up-front, partial Up-front, All Up-Front. This is pretty straightforward, you either pay nothing, some or all when you reserve the instance. There is no cost benefit, that I can see. However, as a new account, you most likely can’t do no up-front.

最后,有三種付款類型:無預付款,部分預付款,全部預付款。 這非常簡單,保留實例時,您無需支付任何費用或全部或全部。 我可以看到沒有成本效益。 但是,作為一個新帳戶,您很可能無法無所事事。

Per AWS Support:

每個AWS支持:

No Upfront Reserved Instances (RIs) can pose a significant billing risk to new accounts, as they’re a contractual obligation to pay monthly for the entire term of the RI. For this reason, new accounts and lightly used accounts are unable to sign up for No Upfront RIs until a successful billing history is built with us.
沒有預先預留的實例(RI)會對新帳戶造成重大的計費風險,因為它們是在整個RI期內按月支付的合同義務。 因此,在與我們建立成功的帳單記錄之前,新帳戶和使用率較低的帳戶將無法注冊No Upfront RI。

You may run into this error if you try and buy a no up-front.

如果您嘗試不先購買,則可能會遇到此錯誤。

Error : Your current quota does not allow you to purchase the required number of reserved instances (Service: AmazonEC2; Status Code: 400; Error Code: ReservedInstancesLimitExceeded;)
錯誤:您當前的配額不允許您購買所需數量的保留實例(服務:AmazonEC2;狀態代碼:400;錯誤代碼:ReservedInstancesLimitExceeded;)

Caveat: For whatever reason, it takes a bit for the the reserved instance to “kick-in” which means the first day of the month always costs more. I’m not sure why this is, but if I figure it out, I’ll update this. See graph below:

注意:無論出于何種原因,保留實例都需要花一些時間才能“啟動”,這意味著該月的第一天總是要花更多的錢。 我不確定為什么會這樣,但是如果找出來,我會進行更新。 參見下圖:

痛點 (Pain Points)

These are just some minor complaints about the overall EBS, which I figured I’d include as an addendum to my original article, in case you’re curious.

這些只是對整個EBS的一些小抱怨,我想我會把它作為我的原始文章的補充內容,以防萬一您感到好奇。

自動更新并不是那么自動 (Automatic updates aren’t really that automatic)

Node versions don’t line up from version to version.

節點版本不會在版本之間排列。

Refer to the step below on how I manage changing Linux versions when Node doesn’t work.

請參閱以下步驟,了解在Node無法正常工作時如何管理更改的Linux版本。

運行多個環境 (Running more than one environment)

Having a development environment and a production running at the same time is easy, but it’s expensive. It doubles it, in fact. Therefore, I usually destroy the dev environment as soon as I’m done with it.

同時擁有一個開發環境和一個生產運行很容易,但是卻很昂貴。 實際上,它是它的兩倍。 因此,我通常在完成開發環境后就立即銷毀它。

文檔太可怕了 (Documentation is horrendous)

AWS is too big for its own good. That is part of why I’m writing this. It was really hard to find answers to my specific needs.

AWS本身就太大了。 這就是為什么我寫這篇文章的一部分。 很難找到滿足我特定需求的答案。

我如何管理更新 (How I manage Updates)

I have two separate instances of my Git repo installed on my laptop. I have one for dev, and one for production.

我在筆記本電腦上安裝了兩個單獨的Git存儲庫實例。 我有一個用于開發,一個用于生產。

I use the dev environment to, well, develop! Pretty straightforward. I use the production folder solely for the purpose of pulling updates from Git master branch, running my webpack configuration and deploying to the production server.

我使用開發環境進行開發! 非常簡單。 我將生產文件夾僅用于從Git master分支提取更新,運行Webpack配置并將其部署到生產服務器的目的。

The reason they are separate is because I can maintain separate elastic beanstalk configurations and not have to worry about deploying to the wrong place.

它們分開的原因是因為我可以維護單獨的彈性beantalk配置,而不必擔心部署到錯誤的位置。

不需要Linux環境更改的更新 (Updates not requiring a Linux Environment change)

For updates not requiring any changes to the linux environment, it’s as simple as running eb deploy in the terminal. It’s amazing and takes about 10 minutes to propagate.

對于不需要對Linux環境進行任何更改的更新,就像在終端中運行eb deploy一樣簡單。 令人驚奇,大約需要10分鐘才能傳播。

需要Linux環境更改的更新 (Updates requiring a Linux Environment change)

Occasionally, you will want to update the Linux environment but will be unable too because AWS is freaking dumb (I’m sure there’s a reason) and only allows certain versions of Node on each Linux build. For this, it’s a bit more complicated, but manageable.

有時,您將需要更新Linux環境,但也將無法更新,因為AWS實在太愚蠢了(我確定是有原因的),并且每個Linux構建上僅允許使用某些版本的Node。 為此,它有點復雜,但易于管理。

  1. Push to production config under new env. The last time I did this, I just created a new instance via eb create prod-1 . It’ll do what it needs to and deploy your app to a new environment.

    推送到新環境下的生產配置。 我上一次這樣做是通過eb create prod-1創建了一個新實例。 它將完成所需的工作,并將您的應用程序部署到新環境中。

  2. Make sure all your updates work. Seems pretty obvious, but this is a good time to make sure there weren’t any hiccups with the new build.

    確保所有更新均有效。 似乎很明顯,但這是確保新版本沒有任何打擾的好時機。
  3. Make sure your env vars are setup correctly. This is sorta part of the previous version, but make sure you’re pulling from the right DB, or whatever.

    確保您的環境變量設置正確。 這是先前版本的一部分,但請確保您從正確的數據庫中提取數據,或進行其他操作。
  4. Make sure your load balancer has the same SSL cert (if applicable). Fun fact, if you try to access an ELB instance in https without a certificate, it will fail!

    確保您的負載均衡器具有相同的SSL證書(如果適用)。 有趣的是,如果您嘗試在https中訪問沒有證書的ELB實例,它將失敗!
  5. Swap the instances. Finally, after everything looks good to go, there’s a button in the console to swap the instance urls. EASY PEASY. You don’t have to change anything in the Route 53, it does it all for you.

    交換實例。 最終,一切看起來都很順利之后,控制臺中就有一個按鈕可以交換實例網址。 十分簡單。 您無需在Route 53中進行任何更改,它會為您完成所有操作。

So, there you have it. How to manage your updates. Pretty easy.

所以你有它。 如何管理您的更新。 挺容易。

最后的想法 (Final Thoughts)

If you have any suggestions to make it cheaper/easier, I would love to hear them. I like the discussion about tools and options just as much as the next developer!

如果您有任何建議讓它更便宜/更容易,我很想聽聽他們。 我和下一個開發人員一樣喜歡關于工具和選項的討論!

With that, I’ll leave with this: Happy coding!

這樣,我就離開了:編碼愉快!

翻譯自: https://www.freecodecamp.org/news/the-reality-of-running-a-production-node-app-on-aws-elastic-beanstalk-55c78b5dad0b/

node aws 內存溢出

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391870.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391870.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391870.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Day2-數據類型

數據類型與內置方法 數據類型 數字字符串列表字典元組集合字符串 1.用途 用來描述某個物體的特征:姓名,性別,愛好等 2.定義方式 變量名 字符串 如:name huazai 3.常用操作和內置方法 1.按索引取值:(只能取…

嵌套路由

父組件不能用精準匹配,否則只組件路由無法展示 轉載于:https://www.cnblogs.com/dianzan/p/11308146.html

leetcode 992. K 個不同整數的子數組(滑動窗口)

給定一個正整數數組 A,如果 A 的某個子數組中不同整數的個數恰好為 K,則稱 A 的這個連續、不一定獨立的子數組為好子數組。 (例如,[1,2,3,1,2] 中有 3 個不同的整數:1,2,以及 3。) …

從完整的新手到通過TensorFlow開發人員證書考試

I recently graduated with a bachelor’s degree in Civil Engineering and was all set to start with a Master’s degree in Transportation Engineering this fall. Unfortunately, my plans got pushed to the winter term because of COVID-19. So as of January this y…

微信開發者平臺如何編寫代碼_編寫超級清晰易讀的代碼的初級開發者指南

微信開發者平臺如何編寫代碼Writing code is one thing, but writing clean, readable code is another thing. But what is “clean code?” I’ve created this short clean code for beginners guide to help you on your way to mastering and understanding the art of c…

【轉】PHP面試題總結

PHP面試總結 PHP基礎1:變量的傳值與引用。 2:變量的類型轉換和判斷類型方法。 3:php運算符優先級,一般是寫出運算符的運算結果。 4:PHP中函數傳參,閉包,判斷輸出的echo,print是不是函…

Winform控件WebBrowser與JS腳本交互

1)在c#中調用js函數 如果要傳值,則可以定義object[]數組。 具體方法如下例子: 首先在js中定義被c#調用的方法: function Messageaa(message) { alert(message); } 在c#調用js方法Messageaa private void button1_Click(object …

從零開始擼一個Kotlin Demo

####前言 自從google將kotlin作為親兒子后就想用它擼一管app玩玩,由于工作原因一直沒時間下手,直到項目上線后才有了空余時間,期間又由于各種各樣煩人的事斷了一個月,現在終于開發完成項目分為服務器和客戶端;服務器用…

移動平均線ma分析_使用動態移動平均線構建交互式庫存量和價格分析圖

移動平均線ma分析I decided to code out my own stock tracking chart despite a wide array of freely available tools that serve the same purpose. Why? Knowledge gain, it’s fun, and because I recognize that a simple project can generate many new ideas. Even t…

敏捷開發創始人_開發人員和技術創始人如何將他們的想法轉化為UI設計

敏捷開發創始人by Simon McCade西蒙麥卡德(Simon McCade) 開發人員和技術創始人如何將他們的想法轉化為UI設計 (How developers and tech founders can turn their ideas into UI design) Discover how to turn a great idea for a product or service into a beautiful UI de…

在ubuntu怎樣修改默認的編碼格式

ubuntu修改系統默認編碼的方法是:1. 參考 /usr/share/i18n/SUPPORTED 編輯/var/lib/locales/supported.d/* gedit /var/lib/locales/supported.d/localgedit /var/lib/locales/supported.d/zh-hans如:more /var/lib/locales/supported.d/localzh_CN GB18…

JAVA中PO,BO,VO,DTO,POJO,Entity

https://my.oschina.net/liaodo/blog/2988512轉載于:https://www.cnblogs.com/dianzan/p/11311217.html

【Lolttery】項目開發日志 (三)維護好一個項目好難

項目的各種配置開始出現混亂的現象了 在只有一個人開發的情況下也開始感受到維護一個項目的難度。 之前明明還好用的東西,轉眼就各種莫名其妙的報錯,完全不知道為什么。 今天一天的工作基本上就是整理各種配置。 再加上之前數據庫設計出現了問題&#xf…

leetcode 567. 字符串的排列(滑動窗口)

給定兩個字符串 s1 和 s2,寫一個函數來判斷 s2 是否包含 s1 的排列。 換句話說,第一個字符串的排列之一是第二個字符串的子串。 示例1: 輸入: s1 “ab” s2 “eidbaooo” 輸出: True 解釋: s2 包含 s1 的排列之一 (“ba”). 解題思路 和s1每個字符…

靜態變數和非靜態變數_統計資料:了解變數

靜態變數和非靜態變數Statistics 101: Understanding the different type of variables.統計101:了解變量的不同類型。 As we enter the latter part of the year 2020, it is safe to say that companies utilize data to assist in making business decisions. F…

代碼走查和代碼審查_如何避免代碼審查陷阱降低生產率

代碼走查和代碼審查Code reviewing is an engineering practice used by many high performing teams. And even though this software practice has many advantages, teams doing code reviews also encounter quite a few code review pitfalls.代碼審查是許多高性能團隊使用…

Zabbix3.2安裝

一、環境 OS: CentOS7.0.1406 Zabbix版本: Zabbix-3.2 下載地址: http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm MySQL版本: 5.6.37 MySQL: http://repo.mysql.com/mysql-community-release-el7-5.noarch.r…

Warensoft Unity3D通信庫使用向導4-SQL SERVER訪問組件使用說明

Warensoft Unity3D通信庫使用向導4-SQL SERVER訪問組件使用說明 (作者:warensoft,有問題請聯系warensoft163.com) 在前一節《warensoft unity3d通信庫使用向導3-建立WarensoftDataService》中已經說明如何配置Warensoft Data Service,從本節開始,將說明…

01-gt;選中UITableViewCell后,Cell中的UILabel的背景顏色變成透明色

解決方案有兩種方法一 -> 新建一個UILabel類, 繼承UILabel, 然后重寫 setBackgroundColor: 方法, 在這個方法里不做任何操作, 讓UILabel的backgroundColor不發生改變.寫在最后, 感謝參考的出處:不是謝志偉StackOverflow: UITableViewCell makes labels background clear whe…

leetcode 703. 數據流中的第 K 大元素(堆)

設計一個找到數據流中第 k 大元素的類(class)。注意是排序后的第 k 大元素,不是第 k 個不同的元素。 請實現 KthLargest 類: KthLargest(int k, int[] nums) 使用整數 k 和整數流 nums 初始化對象。 int add(int val) 將 val 插…