使用Redis的扩展Web ServicesRedis、Web、Services

2023-09-04 04:14:28 作者:当淑女不容易

在我的最新项目,我必须写一个Web服务API来从数据库返回的数据。

In my latest project, I have to write a web service API to return data from a database.

科技股   - 的SQL Server 08 R2   - WCF

Techs are - SQL Server 08 R2 - WCF

的数据,主要是键 - 值对,例如为获得用户X最喜欢的颜色。

The data is mainly key-value pairs, e.g. for get user X's favourite colour.

负载并不庞大,但不是小混混或者 - 约1000请求/秒,峰值

The load isn't massive, but not small-fry either - about 1,000 requests / sec at peak.

我最初的想法是使用Redis的作为缓存,这意味着我们不打的SQL Server经常发生。不过,我一直在试图得到一些基准测试等了此配置的,它不是很大,让我怀疑的Redis将真正提供任何好处,我的问题!

My initial thoughts are to use Redis as the cache, meaning we don't hit SQL Server as often. However I've been trying to get some benchmarks etc out of this configuration, and it's not great, making me wonder if Redis will really offer any benefit for my problem!

架构是   - 独立的数据库服务器   - WCF应用服务器 - IIS   - Redis的Linux的服务器

Architecture is - separate db server - WCF App Server - IIS - Linux Redis server

在我的桌面上打转转,Redis的基准为〜20K OPS /秒​​。伟大的东西。

When playing around on my desktop, the Redis benchmarks at ~ 20K ops / sec. Great stuff.

不过,由于每次调用会经过一个web服务,当我把一个WCF层,我只能拿到300 OPS /秒​​。不是很大。诚然,Web服务客户端,Web服务和数据库都在同一台机器上,这样可能会影响结果!

However, given that each call will go through a web service, when I put a WCF layer I can only get 300 ops / sec. Not great. Admittedly, web service client, web service and database are all on the same machine, so that might skew the results!

此外,移动到真实环境时,网络延迟将是一个主要因素。

Also, when moving to the real environment, network latency will be a major factor.

我不能批量这些要求在任何方式。

I can't batch these requests up in any way.

所以 - 我的问题 - 我所有的使用Redis的作为高速缓存 - 我的知道的我应该使用一个高速缓存在这种情况下 - 但因为我不能有Redis的在同一个盒子作为我的Web服务,那么就不会网络延迟杀的表现?

So - my question - I'm all for using Redis as a cache - I know I should use a cache in this situation - but given that I can't have Redis on the same box as my Web Services then won't network latency kill performance?

任何意见很大AP preciated!

Any advice greatly appreciated!

邓肯

推荐答案

您也可以如使用.NET 4的检查,我认为你应该在的 System.Runtime.Caching 库。

You could also check if using .NET 4 which I think you should the System.Runtime.Caching library.

只要你使用一台服务器为您提供了极大的灵活性。如果你需要一个Web场,或者当事情可以更棘手像同步,失效,过期等,这意味着一些分布式缓存(存储在我看来),支持本地存储(内存通常情况下,本地)和分布式存储。你可以使用这个名称空间也与AppFabric的,以获得所需的缓存。

Gives you great flexibility as soon as you use 1 server. If you need a web farm, or when things can be more tricky like synchronization, invalidation, expire etc, meaning some distributed cache (memory in my opinion), supporting Local store (in-memory usually, local) and distributed store. You could use this namespace too with AppFabric to get the desired caching.

希望这对你的作品。