您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > 基于多线程的高性能服务器程序的设计
1Designofhigh-performanceserverprogramwhichbasedonmultithreadsAbstract:Alongwiththenetworkapplication'srapiddevelopment,thehigh-performanceserverprogramhighlightsitsimportantstatusmoreandmore.Inthearticlehasdesignedahigh-performanceserverprogrambasedonmulti-threads,thustoputsforwardgoodsolutionstoprocessclientconcurrentrequestproblem.FirstlyintroducingtheprincipleofIOCPmodel,then,usingtheSelectmodelandtheIOCPmodelrespectively,putadifferentdesignmethodforthehigh-performanceserverprogramdesign,throughcomparingthetime,CPUutilizationandmemoryutilizationratioandmanyotherparameters,concludedthatIOCPprovidesthebestperformanceofthesystemindesignontheserver.Finallyputsforwarddesignschemeofhigh-performanceserverprogram.Keywords:Selectmodel,IOCPmodel,Concurrencycontrol,Event;flowcontrol1IntroductionAtpresenttherearemanyserverprogramsuse“onetoone”disposingmode,namelyoneclienttakesathread,designsonthearchitectureofserverprogramswhichbasedonthiskindofpatternisverysimple,butsinceusesis“aclient/thread”pattern,thereforethiskindofserverprogramappearsverylowintheperformanceregardingoverathousandclient's2requestconnections,andisalsocostlyonsystemresources.Becausetheoperatingsystemmustcarryonthedispatchforthemassivethreads,itwilllosethemassivesystemresources,andmutexcontrolwillalsobeverydifficult,thedeadlockoccurfrequencywillgreatlyincrease.Nowadaysthehighperformanceserverprogram'sdesignbecomesmoreandmoreimportant,thehighperformanceserverprogram'smainfunctionisthatitcanprocessmassiveconcurrentclient'srequestefficiently,andprocessclient'sdatatimely,simultaneouslygivesthepartoftheresponseinformationbacktotheclientside.Todesignagoodperformanceofserverprogram,mustconsidermanyfactors,likeCPUutilizationratio,Memoryexpensesandsoon.Tobeefficientprocessingconcurrentusersrequest,theserverprogramneedstosolvetwomainproblems:first,handlingtheconcurrentclient'sconnectrequests;second,forconcurrentdataprocessing.Tosolvetheseproblems,itcancreateanequalamountofworkthreadaccordingtothequantityofprocessorcore,andcombineIOCP(Input/OutputCompletionPort,IOCP)model,andtheoperatingsystemofthethreadschedulingmechanism.Inthearticleusingthemulti-threadsandunifiestheIOCPmodeltocarryonthethoroughdiscussiontothehighperformanceserverprogramdesign.32theoryofIOCPmodelIOCP(I/OCompletionPort,Input/OutputCompletionPort)iskindofmechanismthatcanrationallyutilizeandmanagemulti-threads.Byfar,ItisthemostcomplexI/OmodelintheWindowsPlatform.Whentheapplicationmustmanagemultiplesocketsatonetime,thecompletionportmodelprovidesthebestsystemperformanceandthebestretractility,andalsoitisverysuitableforprocessinghundreds,eventhousandsofcustomers.IOCPmodelprovidesanefficientandcomplexKernelObjectWhichcan,byspecifyingthenumberofthreads,overlapinthesocketsendandreceivedeliveryoftherequestprocessingI/O.Itscoreideacanbesimplysummarizedasfollows:Deliveryalltheusers’requeststoamessagequeue,thenuseanumberofpre-createdworkingthreadstoremovethemessagefromthemessagequeueanddealwiththemonebyone.ItcanbeintheserviceofanyI/Ooperationsofanyuser,andonlyasmallnumberofthreadscanhandlealargenumberofI/Orequests,toavoidtheCPUtospendtimeinalargenumberofthreadschedulingandimproveresourceutilization.3Thedesignoftheserverprogram43.1usingIOCPmodeltosettletheconcurrentusersproblem3.1.1concurrentprocessingofmulti-threadsItisknowntoallthatthelargeserversprogramsofhighlyconcurrenthasfacedmanyproblemslikecomplexschema,numerousthreadshardtomanage,concurrentperformancehardtopromote.Therefore,variousplatformshasprovidedsystem-level'sadvancedfacilitiestoassistdeveloperstosolvetheproblem,suchastheplatformofLinuxepoll.JustlikeWindowsplatform,thereisakernelobjectnamedIOCP(completionport),throughwhichwecaneasilycreatehigh-concurrency,highperformance,scalablenetworkserverprograms.Figure2givesthediagramthatusingIOCPmodeltosolvetheissuesthatuserssimultaneouslyrequestedconnectingserver.Figure2IOCPmodeldiagramAdheringtotheprinciplesoflowcoupling,whendesigntheserverprogramswehascreatedfourseparatethreadstodispatchprocessingtheconnectrequestofconcurrentclients.PuttingtousethemechanismofthosefourthreadstohandleuserconnectionrequestscanbeagoodIOCPServerprogramconcurrentusersConnectrequestnConnectrequestoneThread1Thread2Thread3Thread45solutiontodisposeofnumerousconcurrentusers’connectionrequests.3.1.2BufferlistsstrategytosolveconcurrentclientsproblemTofurtheraddressthisissue,wehaveadoptedbufferlistsstrategywhendesigningtheserverprograms.Theschematicdiagramofthisstrategyshowsbelow.Figure3diagramofbufferlistsOncetheclienthasestablished,weinserteditintothebufferlists,sothatotherthreadscanreceivedatasendbytheclient.Inthismode,thesefourthreadsarejusttoconnecttocustomers,ratherthantodealwithcustomerrequests,therebyincreasingthespeedofserverprocessingclientrequests.What’smore,thethreadsdon’thavetowaitforclientdata,whichcausedthemblockinginestablishingconnectionthread.3.1.3MutuallyexclusivecontrolOfcourse,inthosefourthreadsmaycausemutex,soweusecriticalsectiontosolvethemutexproblem.Throughthecriticalsectiontocontroltheoperationsonsharing
本文标题:基于多线程的高性能服务器程序的设计
链接地址:https://www.777doc.com/doc-2574638 .html