Forum Moderators: coopster

Message Too Old, No Replies

memory usage

         

Dunjohn19

6:07 am on Sep 15, 2020 (gmt 0)

5+ Year Member



Hello everyone,

I am wondering if anyone knows of a typical byte range for positive memory usage of a php script? using Google search, i only find questions and answers about how to log memory consumption with memory_get_usage.

I have implemented memory_get_usage on several scripts and i have ranges from 10000 bytes to 89000 bytes. Is this high? I can't find info about byte ranges that are ideal for a php script.

Thank you.

JorgeV

7:04 am on Sep 15, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Hello,

There is nothing such as high or low, it simply depends of what your script is doing.

10KB and 89 KB, this is not a lot anyhow.

The most interesting is, why are you asking this question?

tangor

7:36 am on Sep 15, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Bear in mind that any reporting scripts you insert will add to memory usage ... and provide no real value to your site or the average user.

If you are running out of memory, then by all means add MORE if you own the system, or move to a host that has more available!

Dunjohn19

6:31 pm on Sep 15, 2020 (gmt 0)

5+ Year Member



Hello JorgeV and tangor,

I am not a programmer and i am definitely not a sys admin. Despite these truths, i am builing my own website. I am almost finished with the heavy lifting (bulk of the web programming and design.) I started researching dedicated hosts in my region and alot of hosts only offer 4gb of ram and 100gb hdd. I find this quite low and for 60 euro per month it is ridiculous. I'm thinking about buying my own server system instead. Anyway, i often read php security books and articles. I've recently read forum comments, php programming articles and a book which all mention memory of scripts slowing down servers. I am concerned that my scripts will slow down the site/congest the server. I think that what if i had 1000 users versus memory usage. In this thought even 89kb seems like alot of memory not counting allocated memory.

as a novice, i just want to know what experienced coders have to say about memory usage. one of my larger array driven pages reaches 89kb of memory but 2mb of allocated memory, which seems high to me.

so you think that my scripts are just fine? either buy my own server or find one with atleast 16gb of ram?

JorgeV

9:34 pm on Sep 15, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Understand that your script is (certainly) taking a fraction of second to execute. You will not have thousands of scripts running simultaneously. If you do, there is something wrong somewhere, a bottleneck making the scripts to take too much time to execute.

You can time your scripts using the [php.net...]

60 euros for 4GB / 100 GB is expensive indeed. For this price, you can find servers with 8 cores, 64GB of RAM, 4 x 2TB HDD for example, which, in my opinion, and without hard feeling, is overkill, if you are beginning. Excepting, if you really had a killing idea which will bring instant traffic.

That being said with 4GB of RAM and 100 GB of HDD you should already be able to handle a good chunk of traffic, before considering getting higher server. Now of course, all depends what your site is doing exactly.

tangor

4:46 am on Sep 16, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Shop your hosting possibilities, and don't neglect offerings from other nations ... your code does NOT care where it is installed and connected to the net. Several USA hosts provide sites suitable to 300,000 monthly visitors with 100gb SDD storage for $15/month for example. A step up from that is $25/month which allows up to 100 websites per account, unlimited bandwidth, unlimited email (addresses) and pro support, plus Free SSL ... Shop around!

As JorgeV noted, however, you can get very respectable traffic numbers (hourly) with your described level of hosting hardware...

JorgeV

11:27 am on Sep 16, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



By the way, I'd like to refine my claim that 60 euros for 4GB/100GB is expensive. I assumed we were talking about a dedicated server or VPS which are "unmanaged" (you do everything yourself, and your host only handles hardware/network problems).

If the service is "managed", your host is dealing with OS / Software installation, configuration, etc, and monitoring your server health , then, yes, it has a cost and 60 euros sounds a realistic price for such service.

Also, you have shared hosting and dedicated vpv/server, they are different kind of hosting.


[edited by: not2easy at 11:25 am (utc) on Sep 18, 2020]
[edit reason] typo fix [/edit]

finco

8:41 pm on Sep 18, 2020 (gmt 0)

5+ Year Member



Okay from experience, I'll tell you something:

It is way too early to worry about server memory. It is always advised you start with the smallest you can afford. When you start experiencing issues, the kind of issues you experience will determine the kind of action to take.

For example, you might experience Page B takes so much time to load, then you can investigate that.
Or you might notice when Page A is loading, the entire server halts...
Or when multiple users open Page C at the same time, Apache or whatever web server you use crashes...

Now these issues could require different solutions. And you have o be very very certain that the RAM is the issue before going ahead to upgrade it. Even at that, creating SWAP memory solves an amazing lot of problems.

I run a dating App called Pin Pals. It has over 100k users with over 2000 Active users. It has Instant Messaging also and the IM server runs on the same server. It runs on a 1 GB RAM server and there is no Slow down at all.

I experienced a speed issue sometime last year with a particular query. The query to fetch a user's photos. Adding an index to the images table dramatically dropped the query time.

I knew RAM wasn't the issue because running that query did not have serious effects on the RAM usage.

So like I said, start small and optimize as you grow

NickMNS

1:54 pm on Sep 19, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I agree with @finco. Also fixing issues that are most likely code related by procuring bigger faster hardware is not sustainable. A simple website that displays pages and handles users should not need anything more than a basic server.

You can also relieve some burden from your server by using a CDN service such as CloudFlare that will cache portions or all of your pages. CloudFlare offers a free plan that is more than sufficient for all but the highest traffic websites.

tangor

4:30 am on Sep 21, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



K.I.S.S. is rule number one. Many successful sites operate on low metric systems. It can be done low key hardware. Me? I avoid cloudstuff since that is third party. If THEY fail (for any reason) I fail. Keep it simple, refine your code, and make sure you have optimized everything that can be optimized!

@Dunjohn19 ... what prompted you to insert this code in the first place? Are your geo targets on lower bandwidth?

Dunjohn19

8:56 pm on Sep 27, 2020 (gmt 0)

5+ Year Member



Hi tangor,

I have a fairly large amount of data and i also implement random time limited csrf tokens per private page. Taxonomy of nature is my large data set. I make use of functional programming like flat files along with database tables. I have alot of arrays which hold data used for taxonomical browsing, bookmarking and translating names. I have tried to optimize my code as much as possible. I still read books and articles about php programming and i've recently read about memory problems. I wanted to see how much memory my scripts are using. I don't know of any ideal numbers for memory usage per script. I suppose that my true question becomes how will my web site handle the real world? i use my 16gb ram laptop for testing in xampp. I am a single user and the app works well so far but what about many users and concurrency issues? I really don't know what will happen hen the site goes live. I am new to this level of programming.

Best wishes.

robzilla

8:44 pm on Sep 28, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It depends on how much memory you allocate to PHP. If you want to accommodate 1000 concurrent requests to a script that uses 89,000 bytes of memory, you need to make sure PHP is configured [php.net] to handle ~85 MB of memory + a little overhead. Make it 100 MB. By modern standards, that's tiny. It's about 0.5% of the memory in your laptop.

Anyway, by the time you actually reach 1000 concurrent requests, it's very possible you'll run into other bottlenecks (e.g. CPU, disk I/O) before you run out of memory. I'm italicizing concurrent because unless these are long-running scripts, that's many thousands of simultaneously active users we're talking about.

If it's a random reference point you're after, I just checked the homepage of one of my PHP sites, and memory_get_usage() returned 426440.

MySQL tends to be a much bigger memory hog. Large flat files can be expensive, too, but again... 89,000 is peanuts.