Atslogo tīmekļu servisus ar kešu

Yo!

Sen nekas nav rakstīts... Daudz laika ir aizgājis HHH pasākuma sagatavošanās darbiem, kā arī Community Launch notikumam.

Ta kā TFS timesheet 3. daļa vēl ir rakstīšanas stadijā (1. un 2. apskatāma zem linkiem), šoreiz gribēju pieminēt vienu interesantu lietu, par ko biju piemirsis un varbūt, ka arī Jums šis liksies sen aizmirsts triks :)

Tātad problēmas pamatbūtība bija: ir serviss, kas atgriež baitu plūsmu, kas patiesībā ir Pdf formāta izdruka. Risināmā problēma izvirzīja prasību, ka servisa izsaukumu skaits ir jāsamazina, ja serviss ir izpildījies sekmīgi. Samazināt izsaukumu skaitu nozīmē neizsaukt servisu atkārtoti, ja operāciju ir bijusi sekmīga. Kopīgās diskusijās ar kolēģiem (viens no viņiem bija Andrejs) nonācām pie secinājuma, ka problēmas būtība bija uzstādīta nepareiza. Pēc pāris domu gājieniem un potenciālo nākamo problēmu apspriešanas pie klienta puses keša, mēs izsecinājām, ka pareizā problēmas nostādne ir: atvieglot servisa darbību ar keša palīdzību, neizpildot sūri grūto darbu (izdrukas ģenerācija no kristāla šablona uz Pdf plūsmu), bet gan sekmīgo atbildi kešot servera galā.

Šim nolūkam mums ērti noder WebMethod atribūta papildus iespējas.

Tātad, ja mēs vēlamies sekmīgo servisa izsaukumu iekešot, mums būs nepieciešams iestatīt CacheDuration īpašības vērtību.

Tātad scenārijs ir sekojošs: pieņemsim, ka mums ir serviss, kas saņem 2 parametris, kaut ko ar tiem izdara un atgriež atbildi.

Zemāk ir parādīts tīmekļa servisa kods:

 

[WebMethod (EnableSession = false, CacheDuration = 5)]
public string SessionLessOperation(int param1, string param2)
{
WriteLog ("Doing work in state less manner...");

return string.Format ("You provided in session state '{0}' and '{1}' parameters."
, param1, param2);
}

 

Tīmekļa servisam atbildi ir "jāpatur prātā" 5 sekundes. Lai to mēs vizuāli varētu novērtēt, izveidojam testa klientu mūsu izveidotajam servisam.

Tātad palaižam testa klientu un padarbināt nedaudz to.

image

No testa klienta redzams, ka patiesībā, visas darbības, kas tika izpildītas pēc 41 sekundes līdz 55 - patiesībā neizsauca nemaz tīmekļa servisa darbību, kas nozīmē, ka pieprasījums nemaz neskāra servisu un kešings notiek zemākā līmenī (Asp.Net handlera līmenī).

Nākamais jautājums, kas mani ieinteresēja ir - sesijas. Kas notiek ar sesijām, ja tīmekļa servisam tādas ir deklarētas ar EnableSession = true īpašības palīdzību.

Otra tīmekļa metode izsaktās šāda:

 

[WebMethod(EnableSession = true, CacheDuration = 5)]
public string SessionStateOperation(int param1, string param2)
{
WriteLog("Doing work in session state manner...");

if (Session["test-key"] == null)
{
Session["test-key"] = Guid.NewGuid();
}

return string.Format ("{0}: {1}\t{2}", Session["test-key"], param1, param2);
}

 

Šī metode izvada kādu patvaļīgi ģenerētu sesijas mainīgo, lai mēs pārliecinātos, ka tā ir tā pati sesija.

Testa klienta izsaukumu šāviņš:

image

Kā redzams, tad arī tīmekļa serviss, kas ir ieslēgta sesijas uzglabāšana tīri labi tiek galā ar servera puses kešingu.

Lai vēl konkrētāk pārbaudītu no sesijas atkarīgo servisu kešosas mehānismu ieviesīsim vēlvienu "klientu":

image

Btw, lai sekmīgi strādātu sesijas instance uz servera, nepietiek tikai ar tīru ģenerēto proxy klientu, pēc proxy klienta klases inicializācijas ir jāizpilda šāds kods, lai sekmīgi klients varētu uzglabāt servera ģenerētos sesijas identifikatorus (cookies):

srv.CookieContainer = new CookieContainer();

 

Jautājums: kas notiek ar WCF servisiem un kāds tur ir atbalsts kešingam? Ātri pārmeklējot MSDN specifikācijas, neko prātīgu uz pirmo sitienu neatradu. Tas ko ātrumā varēja izdomāt ir:

  1. Izmantojot HttpRuntime objekti nokļūt līdz Asp.Net kešinga objektam  un izmantot to;
  2. Izmantot kaut kādu trešās puses kešošanas risinājumu (Enterprise Library, piemēram);
  3. Ieviest savu implementāciju kešošanas problēmas risinājumam, parasti tas reducējas līdz objekta Dictionary<string, object> izmantošanai;

Pirmais risinājums nav elegants ar to, ka, tas piešķir zināmu lomu IIS un HTTP terminiem tavā risinājumā. Trešais risinājums parasti beidzas ar 'quick and dirty solution' (ko es parasti gan dēvēju par 'fast non solution' :)), kas parasti neatbalsta keša atkarību mehānismus (dependency policy) vai arī keša izbeigšanās politikas (expiration policy).

However, sameklēju inetā nelielu piemēru, kas risina tieši šo problēmu ar interfeisa IOperationInvoker palīdzību.

Par šo problēmu iespējams, ka nepietika laika norealizēt pietiekoši smuki jeb arī iespēja netika izmantota pietiekoši aktīvi pirms tam, un .Net komanda nolēma risinājumu pataupīt nākamajām versijām.

Toties WCF ir daudzas citas labas īpašības :)

Published Saturday, April 05, 2008 11:45 PM by valdis.iljuconoks

Comments

# a3o0

Thursday, June 24, 2010 4:52 AM by 7

# Web Hosting Companies

Your site is really great ... carry on the great work!

Thursday, June 30, 2011 1:07 AM by Vivienne Mikhail

# cheap viagra professional

This particular blog post provides each light whereby we can easily notice the reality. This is certainly reasonably great just one and offer in-depth specifics. Thanks for this superb content

Wednesday, July 06, 2011 1:08 AM by viagra by mail

# android applications

Hi there, just became aware about your weblog by means of Google, and discovered that it's really informative. I am going to watch out for brussels. I'll appreciate in case you continue this in future. Lots of people today will likely be benefited from your writing. Cheers!

Saturday, July 09, 2011 9:36 AM by Felipe Arterburn

# transformers movies online

Hi there.This document came down to telling, specially since i have obtain appeared to be searching for obtaining gives the topic past Thursday.

Saturday, July 09, 2011 5:41 PM by videos de transformers 3

# lowest price viagra Lansing

My business is generally to successfully posting we very appreciate your written content. The article has truly peaks our appeal to. I'll store your blog post as well as hold verifying kids knowledge.

Sunday, July 17, 2011 12:49 PM by name brand viagra Pompano Beach

# accessrx.com

Sup! That’s a very nice post. I’m very sure I’ll recommend the idea to my very own co-workers.Those of you that article additional articles please e-mail these people to me and my friends.

Saturday, July 30, 2011 3:09 PM by accessrx review

# buy in uk herbal viagra

My own personal our god ! you're going to be master gentleman, i came to be in need of these records all-round cyberspace. Seems as if you’re speedy content composer . take it easy on this page man

Tuesday, August 09, 2011 4:11 AM by generic viagra from india ajanta pharma

# Handy orten gratis

Usually I don't post about sites, however i wants to claim that this extremely very much convinced for me to do this! How exciting, really fine send in.

Wednesday, August 24, 2011 9:55 PM by Handy kostenlos orten

# viagra ingredients

Thank you very much, I’ve been on the lookout for specifics about this method problem for some time combined with yuour own home is a better I’ve found so far. All the same, what exactly in regards to the important thing? Do you find yourself beneficial on the supply?

Saturday, August 27, 2011 12:03 AM by viagra overnight

# viagra soft tablets

Heya.This amazing post got stimulating, specifically since i possess became trying to find trying to get federal grants this method issue ultimate Tuesday.

Saturday, August 27, 2011 2:46 PM by cheap viagra without prescription

# vega sildenafil citrate 100 mg

The site may be the finest marketers.

Friday, September 02, 2011 7:59 PM by 50 mg sildenafil citrate

# handyortung sofort kostenlos

Are you able to email us because of just about any ideas about the method that you made this online site resemble it , I’d regards!

Saturday, September 03, 2011 7:29 AM by handyortung freeware

# generic viagra in british

You've made a number evident things right now there.

Thursday, September 08, 2011 9:20 PM by generic viagra sildenafil

# generic viagra order online

Best wishes, I’ve been on the lookout for info about this matter for a while combined with the ones you have pores and skin look I’ve observed thus far. On the other hand, what precisely in connection with the important point? Will you be encouraging relating to the give?

Friday, September 09, 2011 12:50 AM by generic viagra in united states

# generic viagra and ed

My personal identify is Liz not to mention I’ve a blueprint. I actually research your web site approximately day by day, even so you you’ll notknow that may. That’s given that That i never go away completely some sort of ideas.

Friday, September 09, 2011 4:51 AM by generic viagra united kingdom

# generic viagra soft tab fast

very good online site

Tuesday, September 13, 2011 2:13 PM by generic viagra europe cheap kamagra uk

# generic viagra website

Wonderful web page, I like the rrnternet site appears! The style is wonderful!

Thursday, September 15, 2011 5:28 AM by generic viagra fda approved

# generic viagra now

This particular article increases the soft whereby we'll notice the truthfulness. This is exactly beautiful pleasing a and in-depth facts. I appreciate this unique wonderful document

Wednesday, October 05, 2011 9:25 PM by generic viagra discount tadalafil

# mgCJyBrRqQPZNAMllRx

Friday, December 02, 2011 12:25 PM by Wilman

# re: Atslogo tīmekļu servisus ar kešu

Thanks for your thoughts. It's hpleed me a lot.

Thursday, December 22, 2011 5:00 AM by Ally

# kamagra usa

I do totally share your opinion and I am glad that there are still people who think so. Let's fight for it,because "Opinions cannot survive if one has no chance to fight for them."  kamagra 100mg jelly  <a href="medsildenafil.com/.../a> [b]kamagra direct [/b]

Saturday, January 07, 2012 4:27 AM by kamagra buy

# Read Amazed

I appreciate this post. It is wondrful and very useful.  <a href=onlinepharminfo.com/>erectile dysfunction</a>

Tuesday, January 10, 2012 9:17 PM by what is erectile dysfunction

# best chat rooms for adults adult singles chat

I appreciate this post. It is wondrful and very useful.    

<a href=stardustwebcams.com/.../>chat ave adult</a> cyber chat room

Thursday, January 12, 2012 7:39 PM by camgirls

# best web page hosting budget web hosting

I found this article very interesting and useful. Hope readers will appreciate it.  webspace  <a href="webhostinggeeks.com/">review web hosts </a> [b]cheap cpanel web hosting [/b]

Saturday, January 14, 2012 2:56 PM by web hostings

# kamagra online

Hmmm, I really like your posts, but how can I add your site to my favorites?  kamagra gold 100  <a href=medsildenafil.com/>buy kamagra</a> buy kamagra

Tuesday, January 17, 2012 6:56 PM by kamagra

# website chatrooms 3d chat for adults

Thanks for the post. It helped me to find the best sollutions for my troubles.  adult web chat  <a href="stardustwebcams.com/.../">adult live chat</a> chat rooms for adults no registration

Tuesday, January 31, 2012 7:22 AM by adult webcam

# jzyIiniHph

Friday, February 24, 2012 9:15 AM by M8ZRfJdO

# KboTxQtgsHo

h2972o Major thanks for the blog article.Thanks Again.

Sunday, April 08, 2012 2:26 AM by Motivation to lose weight

Leave a Comment

(obligāts) 
(obligāts) 
(brīvizvēles)
(obligāts)