Welcome Guest, Not a member yet? Register   Sign In
Performance Questions
#1

[eluser]Jagar[/eluser]
Hello everyone,

I have some questions which is bugging me while working on a project right now.

Is there any disadvantages to have many routing done in the routes.php?

Is it a good idea to have one controller do many things, such as admin section, or have it separate?

If it's a good idea to have one controller do many functions, how do you organize and/or redirect request to different function within controller. I currently use if and switches in my index function. Good or bad idea.

That's all the questions I have now, and I'm trying to prevent any problems down the road that may happen with this project.

I'm always looking for advices on good coding and management.

Thank you all and CI Rocks!
#2

[eluser]n0xie[/eluser]
[quote author="Jagar" date="1241465724"]
If it's a good idea to have one controller do many functions, how do you organize and/or redirect request to different function within controller. I currently use if and switches in my index function. Good or bad idea.
[/quote]

Since each function in a controller is supossed to be a seperate 'link/page', I don't really understand why you would need a switch in your index to control flow of your application. Whenever I need to control the paths an user can follow it's usually very logical (from a business logic point of view Wink ).

Let's say someone didn't supply the right credentials: you redirect him to a login controller. Or someone didn't supply the form fields you wanted: you redirect him back to the form and tell him what he did wrong. Another frequent issue comes up when a datasource doesn't return any results. You should always check for this, and you might want to move the user back to the page with a message that his 'query' didn't return any results, or give him a default resultset. All of these cases are pretty clear cut and should only take an 'IF' statement to check if certain criteria are met.

Maybe you can supply an example where one would need a switch to coordinate the flow of the application?
#3

[eluser]Jagar[/eluser]
Thanks n0xie, for your reply!

What you said there makes sense, I currently have the admin section where it does few things within one controller, such as change password, delete admin and other stuff. This project is internal, it will be run on the intranet. So having it to split into different controllers, won't it decrease performance?

Thanks
#4

[eluser]xwero[/eluser]
Every routing on top of the standard controller/method routing is a small bump in the road. If there are enough small bumps you will drive slower not to feel so much trembling. So no routing or redirects are better than a whole bunch of them.

The bigger the file the longer it takes to get read by php. This may not be noticeable but the more users visit that same page the faster they will start to feel it.

But the question is how far are you willing to go to generate everything dynamically? People use cache software and distributed storage on heavy traffic sites. If you want a fast site from the start create as many static snippets as possible and only glue them together instead of accessing the database every time. Of course the content has to be as static as possible for this.
#5

[eluser]Chris Williams[/eluser]
I've used lots of routing in my apps and I haven't noticed anything in speed. I suppose if I put a used some microtime, I would but overall, it should be fine.

If you can set your views to cache, that will be a big help in server speed.
#6

[eluser]Jagar[/eluser]
Thanks for all for the replies, I haven't noticed any decreased performance either, but I'm thinking what if, down the road.

Now I feel comfortable with what I'm doing
#7

[eluser]Dam1an[/eluser]
Tbh, 95% of sites don't need to worry about scalability up front... worry about designing something thats so great that it will need to scale, and eventually you will need to, in which case, great!

I'm not saying you don't need to worry about performance from the very start, but unless doing the easier/more natural way now has a HUGE impact on performance, then go for what you feel most comfortable with

PS. The above has been paraphrased from 37Signals book, Getting Real
#8

[eluser]Jagar[/eluser]
How about having many functions in one model? Good or bad idea?

When loading a model, does CI/PHP checks all the functions or does something with them?

Thanks all for your help
#9

[eluser]Dam1an[/eluser]
When you load a PHP file, the whole file gets loaded (AFAIK), so ideally, having smaller files would benefit performance. Some people suggest arbitrary cutoff, so if a class is more then X lines, cut it in half, but I don't think thats right... You should divide your controllers/libraries/models how ever seems logical to you

If you're interested, I ran some benchmarks yesterday to see how much difference stripping all the comments and whitespace from the core made (therefore reducing the file size), you can see the results here
#10

[eluser]Thorpe Obazee[/eluser]
I believe loading more files also have their toll on the application. So, probably work on the most suitable and logical way for you.




Theme © iAndrew 2016 - Forum software by © MyBB