如何从多个客户端的服务器处理Web服务请求 [英] How does a server handle web service requests from multiple clients

查看:370
本文介绍了如何从多个客户端的服务器处理Web服务请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了一个使用Web服务连接到远程数据库的Andr​​oid应用程序。我工作在本地主机。

I just completed an Android application that uses web services to connect to a remote database. I was working on localhost.

现在,我计划举办我的Web服务的服务器上。比方说,我已经安装在许多不同的客户端的智能手机我的Andr​​oid应用程序。每个智能电话用户呼叫的同时Web服务。

Now, I plan to host my web services on a server. Let's say I have my Android application installed on any number of different client smartphones. Each smartphone user calls the web service at the same time.

现在,服务器如何处理这些请求?是否执行每个请求一个线程?我想了解详细的服务器处理。综合考虑,所有的手机都使用GPRS,会不会有任何形式的延迟在这样的情况呢?

Now how does the server handle these requests? Does it execute one thread per request? I want to know about the server processing in detail. Considering, all phones use GPRS, will there be any sort of delay in such a situation?

顺便说一句,我的Web服务是基于所有的SOAP,我打算以后使用将是一个SQL Server的服务器。我已经使用.NET框架来创建Web服务。

BTW, my web services are all SOAP based and the server I plan to use later will be an SQL Server. I have used .NET framework for creating web services.

推荐答案

它的一般概念,而不是一个特定的Andr​​oid

Its for the general concept, not a Android specific

一般,每个用户发送对网页的HTTP请求。服务器接受请求,并代表他们不同的工人(进程或线程)。

Usually, each of the users sends an HTTP request for the page. The server receives the requests and delegates them to different workers (processes or threads).

根据给出的URL时,服务器读取文件并将其发送回给用户。如果该文件是一个动态的文件诸如PHP文件,该文件之前,它的发回给用户执行

Depending on the URL given, the server reads a file and sends it back to the user. If the file is a dynamic file such as a PHP file, the file is executed before it's sent back to the user.

在所请求的文件已经被送回时,服务器通常将关闭几秒钟后的连接

Once the requested file has been sent back, the server usually closes the connection after a few seconds.

如何Web服务器工作

编辑:

有关HTTP使用TCP是一个基于连接的协议。也就是说,客户端建立一个TCP连接,当他们与服务器通信。

For HTTP uses TCP which is a connection-based protocol. That is, clients establish a TCP connection while they're communicating with the server.

多台客户机可以连接到同一个目的端口在同一目标计算机上在同一时间。服务器刚刚打开了多个同时连接。

Multiple clients are allowed to connect to the same destination port on the same destination machine at the same time. The server just opens up multiple simultaneous connections.

Apache(以及大多数其他HTTP服务器)有一个多处理模块(MPM)。这是负责分配的Apache线程/进程来处理连接。然后,这些进程或线程可以在自己的连接并行运行,不会阻塞对方。 Apache的MPM也倾向于保持开放的多余的线程或进程,即使没有连接都是打开的,这有助于加快后续请求。

Apache (and most other HTTP servers) have a multi-processing module (MPM). This is responsible for allocating Apache threads/processes to handle connections. These processes or threads can then run in parallel on their own connection, without blocking each other. Apache's MPM also tends to keep open "spare" threads or processes even when no connections are open, which helps speed up subsequent requests.

注意:

一个多线程的最常见的问题是比赛条件 - 在这里你两个请求都在做同样的事情(赛车做同样的事情),如果是一个单一的资源,其中之一是要赢。如果他们都插入一条记录到数据库中,不能同时得到相同id--其中一人将获胜。因此,你需要写code实现的其他请求都将在同一时间,可能会修改数据库,写文件或更改全局的时候要小心。

One of the most common issues with multi-threading is "race conditions"-- where you two requests are doing the same thing ("racing" to do the same thing), if it is a single resource, one of them is going to win. If they both insert a record into the database, they can't both get the same id-- one of them will win. So you need to be careful when writing code to realize other requests are going on at the same time and may modify your database, write files or change globals.

这篇关于如何从多个客户端的服务器处理Web服务请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆