TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Question from self-taugh developer, my app is slow. What do I do now?

12 点作者 pototo666超过 3 年前
I built a web app. To be precise, it is a web app inside Wechat ( I am in China).<p>Every day there is around 200 users, and it generates me some ramen profit.<p>Users report that my web app is sometimes slow.<p>I know that there are many plausible causes. But before I jump into the rabbit hole, I want to ask for your kind advice.<p>What is your mental framework to deal with such a problem?<p>FYI, my app:<p>- is built with NodeJS<p>- ran on a cloud server with 2 core CPU, 2G Ram, and 1M bandwidth<p>- is a CRUD app<p>I have learned about building apps from the web, mostly from Udemy and Youtube. Someone has told me to not worry about performance. `Make it work, then make it better`.<p>Now that I have learned how to make it work, how can I learn how to make it better? Do you have any links or materials to share?<p>Thanks a lot.

13 条评论

viraptor超过 3 年前
Your next steps are to figure out 1. what&#x27;s slow, 2. why it&#x27;s slow, and 3. how to fix it.<p>1. You can find that from basic logs - just logging the duration of each request should be enough - either at the app or the web server level. Figure out which endpoint takes more than expected time and in what situation (with specific parameters, specific user, etc.)<p>2. You should be able to use some tracing library or APM to figure out what&#x27;s slow. It could be a call to the database, processing some data, or something else. If it seems obvious what the suspect is, you can also take the timing with a trivial `start=current_time(); the_suspect_thing(); log(current_time()-start);` For APM, datadog has a free trial: <a href="https:&#x2F;&#x2F;www.datadoghq.com&#x2F;product&#x2F;apm&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.datadoghq.com&#x2F;product&#x2F;apm&#x2F;</a> but there are other options too.<p>3. Figure out how you can improve that. For database, often indexes help. For data processing, you can try to do less of it. (filter before processing, cache results, etc.) Whatever is slow, you may need to research more in a specific area. No resource will cover everything, but asking on Stackoverflow is not a bad place to start.
评论 #29713142 未加载
codingdave超过 3 年前
&gt; Users report that my web app is sometimes slow.<p>One wise move is to validate that your app really is slow. Do you experience the same slowdowns? If not, it could be network latency, which is completely dependent on where your ends users are working.<p>I work with many rural end users, and we have noticed that specific areas of the country tend to be where we get complaints of slow apps. We&#x27;ve worked with ISPs in that area to identify and correct old hardware on their network, which improved performance of our app.<p>If you can reproduce the slow behavior, by all means, follow everyone else&#x27;s advice. But just like you would reproduce a bug before fixing it, reproduce the slowness.
评论 #29713163 未加载
评论 #29704269 未加载
wsh超过 3 年前
For a comprehensive review of performance engineering, I’d suggest Brendan Gregg’s book, <i>Systems Performance: Enterprise and the Cloud</i>, now in its second edition. Chapter 2, “Methodologies,” describes several methods—mental frameworks, if you like—for analyzing and resolving performance problems.
评论 #29713177 未加载
idiocrat超过 3 年前
I could not live without a log file.<p>You should create a log file (text file is fine), where you write as much as possible about the program flow: user logged in, user navigates ..., request started, query submitted with parameters, query responded with 1100 records, result processed, result formatted, result delivered, finished request.<p>The log should be appropriately detailed.<p>Correlate the log entries with the user ID, session ID, request ID, thread ID, etc, whatever appropriate.<p>Timestamp the log entries with millisecond times (2021-12-27 14:21:33.512)<p>Watch and observe the request flows over period of days.<p>Perhaps you will see where the problems are.<p>1) Too many records fetched from DB.<p>2) Too slow DB fetch (missing indexes)<p>3) Cold DB caches<p>4) Some exponential loops<p>Instead of text file, you can use a structured log, but a simple text file will quickly give you results.
评论 #29713266 未加载
matt_s超过 3 年前
You will need to identify the slow responses and break down performance of each part to then identify what part of the stack is slow.<p>You don&#x27;t have a lot of resources (RAM&#x2F;CPU) in use so it is possible that&#x27;s the constraint but you have a real learning opportunity to understand better how your tech stack works and learn some performance tuning. Your cloud provider should have some stats for you to see if those things are hitting limits, some simple charts to glance at would at least give you an idea.<p>You mention its a CRUD app so first thing I would look at and spend time on is your SQL queries and analyzing them. The majority of the time in web requests for CRUD apps is in the DB - because it could be loading and reading a file from disk (where the DB stores data) which is typically slower than receiving bytes on a network socket. Learn what `explain plan` means for your database flavor. I am going to venture a guess that you may not have database indexes on some tables. An explain plan for your queries should tell you what indexes, if any, are used.<p>For your front-end you could look into caching services for any JS framework libs, images, etc. assuming there is a way to do that on your network in China. That would reduce the bandwidth usage and if those services work properly, your end users would be downloading those assets from a faster server than you provide.
评论 #29713235 未加载
fivelessminutes超过 3 年前
Node does not prioritize performance.<p>vCPUs don&#x27;t prioritize or guarantee performance.<p>2GB physical ram may not be a lot.<p>1Mb bandwidth (~100KBytes&#x2F;s) may not be a lot if multiple simultaneous users with bulk payloads.<p>Storage may not be performant.<p>Personally as a first step I would just migrate it to a better, dedicated server. Consider the cost of your time to research it. In the West a midrange older dedicated server starts at ~US$30&#x2F;mo. All kinds of potential badness about being in a vm on a shared resource are eliminated.<p>If not, or if that doesn&#x27;t buy you a solution, you must characterize which of the vserver itself, cpu, storage, or bandwidth is the bottleneck.<p>Assuming it&#x27;s linux, I would ssh in and set up prometheus or similar monitoring so you can see it over a week.<p>If no problem, hit it with concurrent transactions until there is a problem. Compare what you have to do to see a problem on a setup on your laptop vs the remote server, you can judge your vserver then.<p>For cpu, look with top how it acts when you give it transactions. Who eats cpu?<p>Memory, top + vmstat.<p>For storage, iostat.<p>Network, netstat -s
评论 #29700946 未加载
评论 #29713286 未加载
NicoJuicy超过 3 年前
1) put a be cdn in front of it<p>2) set your caching in assets and images to preserve bandwidth<p>3) test if your db is the bottleneck.<p>Eg. Some applications have their performance log in a response header ( db: 20 ms, logic : 10 Ms, total: 50 ms)<p>Definitely start profiling and try to up you bandwidth depending on your current online users.
评论 #29713313 未加载
creatornator超过 3 年前
I agree with other comments suggestions:<p>- Use the app, see what is slow from a subjective UX perspective<p>- Profile your code, find hotspots<p>- Use system monitoring to determine if there are any hardware&#x2F;network bottlenecks<p>One thing I would add on these, perhaps a bit more specific: You mention you are using NodeJS, and it is a CRUD app. What is your database? Are you using an ORM? Sometimes the choice of especially an ORM can cause some performance issues behind the nice opaque interface. I have no specific reason to believe this is causing the performance issues for you, but I&#x27;ve had issues myself in the past so thought it might be a helpful suggestion to look into (for example, N+1 query issues).
评论 #29713281 未加载
sidcool超过 3 年前
Apart from what others have mentioned.<p>If you are using NodeJS, it is optimized for I&#x2F;O and not computation. Since it&#x27;s single threaded and async at it&#x27;s core, any blocking computation will impact entire service.<p>One approach could be to profile your app using a myriad of node js profiling libraries. (<a href="https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;docs&#x2F;guides&#x2F;simple-profiling&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;docs&#x2F;guides&#x2F;simple-profiling&#x2F;</a>)<p>If you want a solution, try deploying your JS code as AWS Lambda or GCP Cloud Functions. They may address the issue at lower cost while you fix the issue.
评论 #29713291 未加载
rudasn超过 3 年前
An APM tool could help you find the real cause of the slowness instead of guessing.<p>I used datadog recently to find the exact line of code that would bring CPU to 100%. Since it&#x27;s quite pricey, I only used it for the couple of weeks I needed it.
评论 #29713320 未加载
thrower123超过 3 年前
Learn how to use a profiler, so you know what is actually slow. Find your inefficient hot loops, your N+1 queries, etc.<p>I don&#x27;t know what the standard tool is for node, but there must be one.
评论 #29713319 未加载
AishwaryaVenkat超过 3 年前
First find out why it is slow. If you are not aware of the reason and also the performance got worse, go for any APM solutions that suits your requirement. Atatus has been doing a great job in monitoring with real time insights lately.
randomopining超过 3 年前
Break down each piece of a request -&gt; response trip and add logging or metrics logging to your DB. Use that to find out the weak points and optimize those.