PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Jun 26, 2019 8:06 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sat Jan 03, 2015 10:09 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
Hi,

Although I have no idea how popular my website could become since it is not live yet and won't be until about April 2015, I am almost certain that one server will not be able to handle the load if the website become popular (for sure there will be a problem if it becomes very popular). I figure even if I move to a $400 per month dedicated machine there could be a problem if it becomes very popular. So I have many times tried to figure out how I might deal with this situation by distributing the work across multiple servers (does not help when I have no knowledge or experience with this). I can't give away my website just yet but I have outlined probably the best idea I have come up with so far for dealing with this potential problem. Bearing in mind I have no experience with this problem (let along actual live website experience yet - LOL) maybe someone with this experience might find this approach interesting and might know how this approach might fit in with the real world of dealing with this situation. So here is my idea.

Quote:
 The website will be member based. Some of the processing will involve multiple loops through a few files and I have to do some locking so the PHP server could get busy at times. Such activity in each time zone will occur between 4pm and 7pm all days of the week but on weekends it will also be busy between 10am and 1pm. So initially distribution of activity by time zone will naturally occur and will help delay the need to move to multiple servers. So when the excessive load does come I am thinking of continuing to use this time zone distribution by having different computers for different latitudes with the idea that each latitude computer will have its load distributed by time zones. I had to look up the difference between Latitude and Longitude and I placed what I needed to know in the next paragraph.
 Latitude are the lines that go around the world. Degrees of latitude are 69 miles apart. Latitude starts as 0° at the equator and ends as 90° at the poles. Degrees are divided like a clock into 60 minutes (') and 60 seconds (") to help pinpoint a place between the 69 mile lines.
 So here are the details of my idea. All website members worldwide log in to a single computer that picks up their profile information using PHP. However, at the beginning of the page after the login screen (what I call the control page) it checks the city they are from and the latitude of that city and uses this to decide what latitude computer to load the final information from before it sends them the control page. Here is the part I am not sure about. Maybe to do this jump from the profile computer to the proper latitude computer it would do a header command with a $_GET parameter string before calling the appropriate latitude computer. On the latitude computer a session is started for the user which is initially loaded from the $_GET array (just enough info is provided to keep them going).
 Therefore each time they come back to the control screen this screen is being provided by the latitude computer related to their city rather than the initial profile computer they logged into.
 If they want to update their profile they need to call the profile computer where all profile information is kept and the required information is passed back to the latitude computer where the control screen is pulled up from. A new session is started once they are back on the proper latitude computer.
 If a user goes on a vacation to a different city (and want to use the services of the website) or they move to a different city the computer checks to see the latitude of this city (using Google maps) and if needed the user is taken to that latitude computer where the control screen is provided from. They will be forced to enter the remainder of their information on this new latitude computer (this is detected by that control page that they need to do this). Maybe this could be made more efficient by some sort of FTP transfer of their data to a CSV file on that target latitude computer and once they are on that computer the control screen detects that this file is there and it processes this file to include the new data thus saving the user the need to enter the data again. If they have gone on a simple one month vacation maybe new information which was entered on the 2nd latitude computer could be transferred by FTP to their main latitude computer and as before the control page on that computer would detect this file, use it to load their data files then delete that file. Maybe I could give them instructions to do this transfer across latitude computer during off peak hours.


So that is it. I suspect I need to do some reading on this topic over the next 5 to 10 years to be sure of what to do. I have often wondered if a large RAID setup could avoid needing to do such a distribution of power across machines (with significant programming changes to make it work) or if this type of an idea might be useful for pushing a RAID system to its limits. At this point I may be thinking ahead too much. Right now I am primarily concerned with finishing the website and getting ready to take it live on the cheapest server I can find to test it in the real world with a significant celebration for just having done it to the point that things are running smoothly.

Any thoughts would be greatly appreciated and hopefully this idea or suggestions regarding it may help others.
Thanks,
John


Top
 Profile  
 
PostPosted: Sat Jan 03, 2015 10:48 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
I'm not a huge fan of the latitude based approach. It would likely mean a huge number of servers -- far more than are actually needed -- or grouping latitudes into clusters which may not do much to circumvent the problem. Further, what if your service becomes popular in a given city, say New York or Los Angeles? Massive user base from the same city will all land on the same server. Why not throw a load balancer in front of it and add servers as needed?

Quote:
Some of the processing will involve multiple loops through a few files and I have to do some locking so the PHP server could get busy at times

This sounds like a much bigger problem to me.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Sat Jan 03, 2015 11:33 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13590
Location: New York, NY, US
There are are pretty standard architectures for this with cache servers on the front edge, backed by load balancers that distribute requests to multiple application servers backed by multiple database servers.

The fact that you mention reading files rather than using a database and looping through those files raises a red flag.

I would recommend building a well coded application and worrying about scaling when it becomes an actual problem.

Actually, I think the Worse is Better approach may be the way to go. Just build something as quickly a possible that does what you want and see if the world actually loves it. If they do, then hire pros with all the money you are making. If they don't then you have lost the minimum amount of time and can move on to your next great idea. PHP excels at this e.g., Facebook, Wikipedia, WordPress, etc., etc., etc.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sun Jan 04, 2015 11:43 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine
Apart from good points above I need to point that timezones (roughly) correlate to longitude, not latitude:
Attachment:
ezgif.com-resize (1).gif
ezgif.com-resize (1).gif [ 1.01 MiB | Viewed 8027 times ]


Top
 Profile  
 
PostPosted: Fri Jan 09, 2015 10:55 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
Hi guys! Sorry for the late response, I could have sworn I was getting email notices to this forum but I just checked very carefully and I got no responses. I had assumed lack of response was due to the Christmas season and I kind of forgot about my post. Obviously I was wrong. I checked my profile stuff and the "Edit Posting defaults" "Notify me upon replies by default:" setting is yes. I also tried real hard and could not find my email address. It seems strange. It should be in the profile area. Anyway, back to topic.

Thanks so much for the responses. They have been very helpful. I will try to respond in logical sequence.

Quote:
The fact that you mention reading files rather than using a database and looping through those files raises a red flag.


regarding the above, I guess my wording was not clear. All data is in a MySql database. When I say loop through I mean do a query then loop the query data which is in memory to update all or select records from that query.

Quote:
I'm not a huge fan of the latitude based approach. It would likely mean a huge number of servers -- far more than are actually needed -- or grouping latitudes into clusters which may not do much to circumvent the problem. Further, what if your service becomes popular in a given city, say New York or Los Angeles? Massive user base from the same city will all land on the same server. Why not throw a load balancer in front of it and add servers as needed?


Regarding the above I totally agree with the idea of one city getting too busy. I think my problem is I am not clear on how the database would be distributed across multiple servers. Having to split specific data to a different server in my mind is too difficult and likely to fail. Is MySql (in conjunction with a load balancer) smart enough to automatically distribute data and know what server to go to (in other words it makes it so I can program it as if all data is on one disk drive)? Is this what a load balancer does? Maybe I need to ask google some questions so I don't take up too much of everyone's time. Its a bit hard to create a google search when I am a beginner in this server distribution topic.

Quote:
I would recommend building a well coded application and worrying about scaling when it becomes an actual problem.

Actually, I think the Worse is Better approach may be the way to go. Just build something as quickly a possible that does what you want and see if the world actually loves it. If they do, then hire pros with all the money you are making. If they don't then you have lost the minimum amount of time and can move on to your next great idea. PHP excels at this e.g., Facebook, Wikipedia, WordPress, etc., etc., etc.


Regarding the above, I love this comment because this is basically what I am doing. I have been Learning what I need to learn as I need to learn it and just getting things to work and not learning too much beyond that (there is just not enough time and money for such luxuries). As I get my website to work in the real world bit by bit I can start promoting it and hopefully upgrading it and learning what I need as I go so that the waits on pages are not too long. This fun part starts about March/April. It will be a matter of promoting it in balance with revenue increase and my ability to manage it and my ability to pay for experts. Basically what you said.

Quote:
Apart from good points above I need to point that timezones (roughly) correlate to longitude, not latitude:


Regarding the above. Yes, I understand this. My wording may not have been clear. There is not much point it talking about it now I guess since I think the other comments eliminate the latitude idea which for me is great news. I need to learn about load balancing so if I do make enough money to hire experts I at least have some idea of what they are doing and I can sense a good one from a bad one.

Thanks again for the great comments. It makes me feel a bit better about what I have done so far.
John


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group