mod_harbour benchmark utility using CURL

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

mod_harbour benchmark utility using CURL

Postby Antonio Linares » Tue Feb 18, 2020 11:13 am

Code: Select all  Expand view
#include "/home/user/harbour/contrib/hbcurl/hbcurl.ch"

function Main()

   local n

   for n = 1 to 10
     hb_threadStart( @ReadWeb() )
   next

   hb_threadWaitForAll()
   InKey( 1 )

return nil  

function ReadWeb()
   
    local hCurl, cBuffer := ""
    local cUrl  := "http://www.modharbour.org/modharbour_samples/info.prg"

    curl_global_init() 
   
    if ! empty( hCurl := curl_easy_init() )
        curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
        curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )

        if curl_easy_perform( hCurl ) == 0
           uValue = curl_easy_dl_buff_get( hCurl )
           ? 'Thread: ', hb_threadId(), 'Get: ', Len( uValue )
        endif
    endif
   
    curl_global_cleanup()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: mod_harbour benchmark utility using CURL

Postby Antonio Linares » Tue Feb 18, 2020 11:28 am

Another version by Carles:

Code: Select all  Expand view
function Main()

   local n
   local aThreads := {}

   Aadd( aThreads, hb_threadStart( @Slow() ) )
   
   for n = 1 to 10
      Aadd( aThreads, hb_threadStart( @ReadWeb() ) )
   next
   
   nThreads := len( aThreads )
   
   while ( j := hb_threadWait( aThreads, 0.1, .T.) ) <> nThreads
        ? 'Executed => ' , j
   end
   
   ? 'Executed All => ', nThreads
   
   hb_threadWaitForAll()
   InKey( 1 )  

return nil  

function Slow()
    inkey(3)
    ? 'Thread: ', hb_threadId(), 'Slow Done'
retu nil

function ReadWeb()
   
    local hCurl, cBuffer := ""
    local cUrl  := "http://www.modharbour.org/modharbour_samples/info.prg"

    curl_global_init() 
   
    if ! empty( hCurl := curl_easy_init() )
        curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
        curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )

        if curl_easy_perform( hCurl ) == 0
            uValue := curl_easy_dl_buff_get( hCurl )
            ? 'Thread: ', hb_threadId(), 'Get: ' , len( uValue)
           
        endif
    endif
   
    curl_global_cleanup()

return nil  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 9 guests