Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
f36394a4
Commit
f36394a4
authored
Mar 13, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated loadbalancer plugin to use endpoints
Unittests not yet updated...
parent
b76a148e
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
140 deletions
+119
-140
examples/7.1-plugin-loadbalancer.php
examples/7.1-plugin-loadbalancer.php
+15
-14
library/Solarium/Core/Client/Client.php
library/Solarium/Core/Client/Client.php
+1
-1
library/Solarium/Plugin/Loadbalancer/Loadbalancer.php
library/Solarium/Plugin/Loadbalancer/Loadbalancer.php
+103
-125
No files found.
examples/7.1-plugin-loadbalancer.php
View file @
f36394a4
...
...
@@ -3,16 +3,17 @@ require('init.php');
htmlHeader
();
// create a client instance and
get loadbalancer plugin instance
// create a client instance and
create endpoints
$client
=
new
Solarium\Client
(
$config
);
$loadbalancer
=
$client
->
getPlugin
(
'loadbalancer'
);
$endpoint1
=
$client
->
createEndpoint
(
'local1'
);
//normally you would add endpoint specific settings...
$endpoint2
=
$client
->
createEndpoint
(
'local2'
);
$endpoint3
=
$client
->
createEndpoint
(
'local3'
);
// apply loadbalancer settings
$optionsSolrOne
=
array
(
'host'
=>
'127.0.0.1'
,
'port'
=>
8983
);
$optionsSolrTwo
=
array
(
'host'
=>
'127.0.0.1'
,
'port'
=>
7574
);
$loadbalancer
->
addServer
(
'solr1'
,
$optionsSolrOne
,
100
);
$loadbalancer
->
addServer
(
'solr2'
,
$optionsSolrTwo
,
200
);
$loadbalancer
->
addServer
(
'solr3'
,
$optionsSolrTwo
,
1
);
// get loadbalancer plugin instance and add endpoints
$loadbalancer
=
$client
->
getPlugin
(
'loadbalancer'
);
$loadbalancer
->
addEndpoint
(
$endpoint1
,
100
);
$loadbalancer
->
addEndpoint
(
$endpoint2
,
100
);
$loadbalancer
->
addEndpoint
(
$endpoint3
,
1
);
// create a basic query to execute
$query
=
$client
->
createSelect
();
...
...
@@ -22,26 +23,26 @@ for($i=1; $i<=8; $i++) {
$resultset
=
$client
->
select
(
$query
);
echo
'Query execution #'
.
$i
.
'<br/>'
;
echo
'NumFound: '
.
$resultset
->
getNumFound
()
.
'<br/>'
;
echo
'Server: '
.
$loadbalancer
->
getLast
ServerKey
()
.
'<hr/>'
;
echo
'Server: '
.
$loadbalancer
->
getLast
Endpoint
()
.
'<hr/>'
;
}
// force a server for a query (normally solr 3 is extremely unlikely based on it's weight)
$loadbalancer
->
setForced
ServerForNextQuery
(
'solr
3'
);
$loadbalancer
->
setForced
EndpointForNextQuery
(
'local
3'
);
$resultset
=
$client
->
select
(
$query
);
echo
'Query execution with server forced to
solr
3<br/>'
;
echo
'Query execution with server forced to
local
3<br/>'
;
echo
'NumFound: '
.
$resultset
->
getNumFound
()
.
'<br/>'
;
echo
'Server: '
.
$loadbalancer
->
getLast
ServerKey
()
.
'<hr/>'
;
echo
'Server: '
.
$loadbalancer
->
getLast
Endpoint
()
.
'<hr/>'
;
// test a ping query
$query
=
$client
->
createPing
();
$client
->
ping
(
$query
);
echo
'Loadbalanced ping query, should display a loadbalancing server:<br/>'
;
echo
'Ping server: '
.
$loadbalancer
->
getLast
ServerKey
()
.
'<hr/>'
;
echo
'Ping server: '
.
$loadbalancer
->
getLast
Endpoint
()
.
'<hr/>'
;
// exclude ping query from loadbalancing
$loadbalancer
->
addBlockedQueryType
(
Solarium\Client
::
QUERY_PING
);
$client
->
ping
(
$query
);
echo
'Non-loadbalanced ping query, should not display a loadbalancing server:<br/>'
;
echo
'Ping server: '
.
$loadbalancer
->
getLast
ServerKey
()
.
'<hr/>'
;
echo
'Ping server: '
.
$loadbalancer
->
getLast
Endpoint
()
.
'<hr/>'
;
htmlFooter
();
\ No newline at end of file
library/Solarium/Core/Client/Client.php
View file @
f36394a4
...
...
@@ -300,7 +300,7 @@ class Client extends Configurable
* Get an endpoint by key
*
* @param string $key
* @return
string
* @return
Endpoint
*/
public
function
getEndpoint
(
$key
=
null
)
{
...
...
library/Solarium/Plugin/Loadbalancer/Loadbalancer.php
View file @
f36394a4
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment