New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Looking for help to optimize server for traffic with failover running shitty php app(paid)
I have some issue at my work where I am not able to scale up resources because developer at my place sucks, they are hardly of any help so all I can do is mess around with server to handle traffic surges but lately I am loosing the battle. This is a failover setup. From coding side, nothing much can be done.
I am looking for someone with experience in failover / redundancy things, server optimization running PHP apps to help me to get it right. I am willing to pay if demand is justified.
Please understand that I can only go ahead with a person who have suitable track-record at LET.
Comments
you need Load balancing. can be done with haproxy if you're familiar with it.
I am sure there are many system admin around who can help
edit: and most likely, mysql is going crazy so you may need to setup multi master cluster as well. may be something like this..
what kind of script? Do they wrote in Laravel?
No, there is no framework used and it just works , have seen code a little, its disaster in terms of performance. But nothing can be done there as of now.
Yes, we need load balancing and did with nginx but things aren't smooth. Btw, mysql is fine, issue with bad PHP and the way it works.
>
how many servers and what config and how much load? vpses or dedicated?
A load balancer, 1 dedicated box, 1 vps,
However, thing is that I need someone who has actually successfully done things, there are some limitation that we have to do only with limited IPs assigned as well limited budget.
Your multiple PHP workers might have local state.
If the site uses session cookies, enable sticky/persistent sessions on NGINX. Try http://tengine.taobao.org/document/http_upstream_session_sticky.html (Taobao's NGINX fork). Alternately payup for NGINX Plus which also comes with sticky session support.
If it's just one or two scripts that are causing a bottleneck, just paste them on pastebin stripping out any security aspects, and there's maybe a 2-minute obvious thing that can be singled out and solved.
I don't understand how having load balancer will fix shitty code.
By distributing load caused bad script hence more traffic can be served.
Thanks Ricardo, however, have sneaked into code, the way things work means it need whole rewrite. And because it is working in their development environment where there is no traffic, they think it is good.
Why I am asking for help here is to find a solution to handle traffic surges without modifying code at the moment yet also finding what exactly is causing havoc here. I will check out into your suggestion to see what it can do .
You've at least identified it's the scriping that's the issue. If we can assume it's not a genuine lack of hardware, it'd certainly help that you can identify specific parts of the coding, otherwise someone will have to get familiar with your entire piece of software which'd potentially take a lot more time, depending on size.
I should have explained it better.
If you are stuck with some PHP code, throw more hardware(CPU+memory) at it by running multiple copies behind NGINX. Eg:-
I assumed you already had such a setup from previous posts. If you are having problems with such a setup, it could be because the PHP code uses local state - stored in local variables, and not in the database. For instance, session information may be stored in local memory and not fetched from Mysql/Redis each time.
If your code is not designed for scalability, it would expect all requests from a particular session to come to it. For such a case, force the loadbalancer to have sticky sessions - once a particular PHP instance was used to create a new session (for a visitor from the web), then all further requests for that session will get re-routed to the same PHP instance. NGINX is already a reasonable loadbalancer, and the Tengine fork has sticky session support.
I know its bad scripting because can see inefficient routines everywhere, hardly any use of caching as well all kind of bad practice of coding is there. It just works and thats it. However, bigger hardware is always the easy solution but thing is that few months back it was upgraded, which increased capacity around 4x without code change but again, on promotions they need sometimes 10x of current resources, but budget is limited. So now I am looking for someone experienced enough who can advice me best possible setup seeing current constraints and guide me if I need exact help.
We can achieve sticky session kind of effect by ip_hash
However ran into some other issues and hence asked here.
Nothing you can do when your company hires a POS dev.
Well, for time being.. :-P
Hopefully things will change..
I guess I need to make another post with clear intention to get paid help..
If you web app has cookies that differentiate between guest and logged in users, you could setup some for of caching tiers for hot & cold caching for guests based on detected cookies. That at least would divide up your traffic into 2 sets to deal with - logged in vs guest traffic. Then you can ease the load on PHP for guest traffic at least to more manageable levels. Then work on logged in user traffic. So using a mix of nginx proxy_cache/fastcgi_cache based on custom key / cookie definitions. Also if you can use PHP 7.1.x instead of PHP 5.6 + Zend Opcache as it's twice as fast.
Thanks but issue is that currently can't expect much changes on coding side..
Like others have said , cache mysql queries , redis is dead simple to setup and extremely helpfull when it comes to giving mysql a rest.
Also , add/enable opcache for your php scripts.
I manage few sites with decent traffic and user interaction , what i do it send only write requests to mysql , and all the read requests to redis (RAM is cheap). That way , i have a backup of my data and at the same time able to deliver read requests at very good speeds.
It would also help if you could post the number of queries your app is serving/day and what is the config of your server(s) in use.
MySQL usage is almost nil, disk usage is almost 0 most of the time, thing is that the script is badly written, I can see each call takes few second and when there is traffic.. either have lots hardware power or optimize script.. for time being, optimization is not option. The complete code rewrite is being reconsidered but not at the moment.
You can try setting up and using hhvm for PHP 5.6 or upgrade to 7.0/7.1