如何使用 PHP 创建负载均衡器类型的逻辑?
我希望利用我的无限共享主机来创建几个可以将处理任务卸载到的小型共享主机帐户。 因此,我需要在 PHP 中创建一些逻辑来创建负载均衡器的基础知识。
我有 4 个共享帐户,一个是主站点,另外 3 个是处理服务器帐户。 请查看图片。
我想知道如何确定将下一个处理作业传递到哪台服务器? 我是否保留我传递到的最后一个服务器的变量并从一个服务器转到另一个服务器? 等等。
最好的方法是什么?
I wish to make use of my unlimited shared hosting to create several small shared hosting accounts that I can offload processing to. So I need to create some logic in PHP to create the basics of a Load Balancer.
I have 4 shared accounts, one is the main site and the other 3 is the processing server accounts. Please see image.
I want to know how I can determine which server to pass the next processing job to? Do I keep a variable of the last server I passed to and go from one to the other? etc.
What is the best method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的 KISS Tinpot 建议是在提交表单时使用 JavaScript 来随机选择服务器。
上传页面将使用的可用服务器列表应作为主服务器的 JS 文件提供。 cron 作业应定期更新此列表,以确保只有活动的服务器可供选择。
简单示例:
servers.js(托管在主服务器上,自动生成):
upload.html:
My KISS Tinpot suggestion would be to use JavaScript upon submitting the form to select a server at random.
A list available servers that the upload page would use should be served up as a JS file from the main server. A cron job should update this list periodically to ensure only alive servers are up for selection.
Simple example:
servers.js (hosted on main server, auto-generated):
upload.html:
可能会摆脱困境,但是,您可以使用随机请求的方法来重现循环/dns/吗?
Might be going off the hook, but, could you reproduct round-robin / dns / using a method of random requests?
请重新考虑一下,你想要放弃的那些工作是什么? 什么样的工作。
首先,对于答案,您可以根据作业的某些参数均匀地拆分作业,例如,每个参数都带有一个提交作业的用户名字段。 您在这些服务器之间划分用户群,并将适当的请求发送到指定的服务器。
另一种策略(更复杂的策略)是负载均衡器从这 3 个工作线程接收一些基本信息,这些信息将告诉每个工作线程的负载,而不是根据该负载分配作业。
我个人会选择复杂的方法,当然,如果给定的主题需要这样做的话。
Please reconsider, what are those jobs you're trying to break up? What kind of jobs.
First for the answer, you could split jobs evenly based on some parameter of the job, like let's say, each parameter comes with a username field, that submitted the job. You split your userbase between those servers and send appropriate request to designated server.
Other strategy - more complex one - would be for the load balancer to recive some basic info from those 3 workers, which would tell the load of each of them, than distribute jobs basing on that load.
I personaly would go for the complex method, of course if given subject would require that.