Grid computing has made it possible for users to perform computationally expensive applications on dynamically acquired distributed resources. Users can combine data and analysis components distributed over the globe to build new, complex applications. Distributed query processing is now an established way of structuring computation and analysis over structured data, and well-used Grid tools like OGSA-DAI and OGSA-DQP provide respectively a common interface to heterogeneous databases and a way of exploiting distributed resources. Unfortunately, the potential benefits are often undermined when databases and computational services are distributed over a wide area resulting in significant computation and communication costs. This paper describes a system that addresses this by allowing key components including query operators, computational services and databases to be dynamically deployed in virtual machines over a Grid. Databases are replicated within virtual machines which are automatically deployed by the system which monitors the performance over a set of queries using a feedback mechanism. Results of internet-scale experiments are presented to show the performance benefits.