Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter - resource intensive?
#1

[eluser]mikemike[/eluser]
Hi guys,

Myself and a colleague have been rolling out CI sites for a while now and use it in most of our projects. We've done some small projects recently that have exploded in popularity. We end up getting around 400,000 visits per day across several small (in code size) sites.

Recently, however, we've had some server issues. We have quite a hefty server for these sites. We have plenty of spare RAM and HD space, but it appears we're lacking substantially in CPU power. The server spec is below:
Code:
Dedicated CPU
2.4GHz
RAM
1504MB
Storage
40GB
Bandwidth
1000GB

These sites are probably best off in some sort of bespoke system. The system is basically just a series of plain text pages with a maximum of 100 words on each. The only images on the site are those from the layout - of which there are about 5, largest being the logo at 25kb. The others are 2kb or less.

We chose CI for these small projects for scalability. We know we can easily plug in functionality and we know the framework inside out. We really don't want to have to re-write the systems in something bespoke and fast, but CI is becoming far too sluggish for us to use.

My question is, what can we do to help improve the speed of CI with CPU in mind? Are there any best practices? We're not currently using caching, does that make a huge difference?

It might be worth noting that it was our hosts who gave us the information on CI using lots of CPU, so if you feel that CI isn't resource intensive at all, then please let us know!

Thanks
#2

[eluser]WanWizard[/eluser]
Images don't slow down CI, they are served by the file system (unless you route image requests through CI as well), and besides that, they are (or should be) cached client side.

If the application does nothing more than serve views with static text, there isn't a lot of code that actually runs. RAM might be an issue if you load libraries and helpers you don't need, or if you have extended a lot of core libraries, which could have an influence on the number of concurrent processes the webserver can support.

How did you determine there's plenty of RAM but lack of CPU? Did you monitor/measure that?

Before you start tinkering, first try to find the source of the problem. Use FF and Firebug, and request some pages. Where does the Net tab of Firebug say the delay is? Do you have to wait long for a response? Is the reponse quick but does it take a long time for everything to arrive? The first is an indication of a slow webserver (or application), the second a bandwidth/latency issue.

Latency can only be solved by your ISP, or by moving to a hoster with a better network. If it's the server, you will have to look in detail what the problem exactly is. In another thread here it was shown that the correct apache config can make the difference between being able to server 10 or 1000 req/sec...
#3

[eluser]Greg Aker[/eluser]
are these 400k total page views? Or 400k visitors a day? over 24 hours that's about 4-5 page hits a second? using a single dedicated server, it may be too much for the server to handle. There are quite a few blogs/talks out there on CI Benchmarks, and yes, CI is screaming fast. However, inefficient controller/model/library code + the way things are handled in views can bring a site to a crawl.

Are you running a database on these sites? Is the db running on the same server? What about BIND or a mail server? That running there too? Adding up all those things can definitely be a server killer, especially when you start to get some traffic.

-greg
#4

[eluser]n0xie[/eluser]
Quote:Recently, however, we’ve had some server issues.
Define server issues.

Also give more specific info. Do you run a database? What version of PHP are you running? Do you run Apache? If all your pages are simple static pages, why not use Nginx or Lighttp? Do you have opt-code cache enabled? Why aren't you caching your pages if they are simple static content? Did you set your Expires/Cache Control headers right? What does Yslow tell you? What does Firebug NET tell you?

Finding bottlenecks in servers can be a tedious job and requires a specialist to do right. We need a lot more information, for us to have any clue what the problem might. Optimizing only works if you know WHAT to optimize or if it even makes sense to optimize: it might be the server just can't cope with 400k views/day on 1 core.

Here is a good starting place
#5

[eluser]echoDreamz[/eluser]
Well here a are a few things to add...

Is this a truely dedicated server? Or is this a VPS or a semi-dedicated box?
Is this a server class processor like a XEON or a Opteron, or is it a budget CPU (Celeron, Pentium 4, Sempron etc.)
Why type of HDD is in this machine? IDE based, SATA, SCSI?
What OS / Web server are you running?
What other, if any services are on this machine?
-------------
I run a very busy site powered by CI, I wont give the link as its NSFW, but it gets ~300k uniques a month and my server specs are as follows (bare in mind this server also runs 5 other sites that together get ~100k hits a month | 2 are .NET based (DotNetNuke) 1 is Joomla powered and the other 2 are CI based).

3.0GHz Dual Intel XEON Processors with HT
4GB DDR2 RAM @ 800Mhz (ECC)
4x 250GB SATA2 in RAID 0+1
Dual Intel Pro 1000 NICs
4TB Bandwidth
Server 2003 R2 Std. Edition
IIS6 with PHP 5.2.14 running under FastCGI (all but 2 sites run dedicated application pools)

and my CPU usage stays ~35% constant spikes to maybe 70%.
Note that this server also runs MySQL 5.1.50, SmarterMail v7, SimpleDNS 5.2, Gene6FTP and a VisualSVN server.


First take notice if you are running a "Budget" class CPU like listed above, cheaper CPUs give cheaper performance to their server class friends like the Xeon and the Opterons. If you have alot of disk I/O using better drives with lower seek times, and better interfaces will assist with this too. Especially if you are using low-end IDE based drives. SATA drives do well, as do SCSI drives. RAID can also hugely pump the performance of disk i/o as you have >=2 drives serving data as 1. I have also worked with dedicated clients who have "cheap" network cards such as realtek that simply cannot handle the high demand of network throughput on demanding sites, switching over to better cards such as Intel Pro 100/1000 solved the issue immediately.

Give some more insite into your box and we can assist you more.
#6

[eluser]mikemike[/eluser]
Thanks for all of the replies.

The server is a cloud server, so in a sense it's a VPS I guess.

By server problems, I mean the server was going down - not responding to pings or any other sorts of requests.

We receive around 400,000 visits, not page views. Analytics says we get an average of 2.7 page views per visit.

The pages served ARE NOT static. I said they were plain text, but not static. Everything is database driven. We run PHP 5.3 and MySQL 5.1. The server has cPanel installed, so it comes with all the usual crap you'd expect on a production server - mail, DBMS, and all the frills. Appreciate this does slow things down, but not that much, surely? We have very very low traffic with regards to mail.

We've been told by our hosts that the RAM is plentiful, and that the CPU is running short. I've spent some time looking at 'top' through various times of the day.

We also have some Facebook interaction on some of the pages, but this only occurs when the user requests it - they're simple Facebook 'like' buttons, and they're very responsive. These only send and receive a tiny amount of data, so should have next to no impact on the server, as far as I can tell.

I don't think it's a network issue, or why would the server go down? Surely if the network was the bottleneck then that would take load off the server by stopping it being hammered to it's full potential?

Our hosts (this is a fully managed solution) have told us they've fully optimised the Apache configs. As this is all a little bit beyond us, we're unsure.
#7

[eluser]Greg Aker[/eluser]
I've seen some similar things with servers being run with control panels. IN HA production settings, you generally see Mail, DBs, etc on their own dedicated systems. all of those things are just draining from resources apache can use. Honestly, you're probably the point you need a clustered system in place. There is much more to optimizing a system than having apache optimized. what about MySQL configurations? If you're just using stock settings, you're definitely not getting what you should out of the system.

If you want managed, load balanced hosting, I encourage you to speak our (EllisLabs) sister company, EngineHosting about a load balanced VPS setup. email them at: [email protected]

-greg
#8

[eluser]echoDreamz[/eluser]
[quote author="Greg Aker" date="1284672250"]I've seen some similar things with servers being run with control panels. IN HA production settings, you generally see Mail, DBs, etc on their own dedicated systems. all of those things are just draining from resources apache can use. Honestly, you're probably the point you need a clustered system in place. There is much more to optimizing a system than having apache optimized. what about MySQL configurations? If you're just using stock settings, you're definitely not getting what you should out of the system.

If you want managed, load balanced hosting, I encourage you to speak our (EllisLabs) sister company, EngineHosting about a load balanced VPS setup. email them at: [email protected]

-greg[/quote]

You can also look elsewhere for similar or better performance for less cost. EngineHosting is nuts on pricing. $300 for the basic VPS is crazy, the specs are very very low for $300 a month. Checkout GoGrid, PowerVPS, VPS.net, there are many.
#9

[eluser]WanWizard[/eluser]
Is that what they charge? Woops... You can get a quad-core dedicated machine for less that $100...
#10

[eluser]echoDreamz[/eluser]
Yes, I love CI, however they are crazy with their prices lol for hosting. Even their shared hosting is overpriced for the resources you get.

They are far behind on PHP too. Their shared services run PHP v5.1.6, which is well behind the current release of 5.2.14. 5.1.6 is 4 years old... that cannot be good for stability and security.




Theme © iAndrew 2016 - Forum software by © MyBB