Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
K
key_value-server
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
amir.yosef
key_value-server
Commits
8abed585
You need to sign in or sign up before continuing.
Commit
8abed585
authored
Aug 12, 2024
by
amir.yosef
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disabling vector api
parent
a87b5250
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
50 deletions
+49
-50
vcs.xml
.idea/vcs.xml
+0
-1
SetCommand.java
src/command/SetCommand.java
+4
-4
ClientCommandHandler.java
src/handlers/ClientCommandHandler.java
+4
-4
Storage.java
src/storage/Storage.java
+41
-41
No files found.
.idea/vcs.xml
View file @
8abed585
...
...
@@ -2,6 +2,5 @@
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
<mapping
directory=
"$PROJECT_DIR$/key_value-server"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
src/command/SetCommand.java
View file @
8abed585
...
...
@@ -16,10 +16,10 @@ public class SetCommand implements CommandHandler {
public
void
execute
(
List
<
String
>
commands
,
OutputStream
os
)
{
Map
<
String
,
String
>
commandsMap
=
new
HashMap
<>();
//
//
for (int i = 2; i < commands.size(); i += 2) {
//
commandsMap.put(commands.get(i).toLowerCase(), commands.get(i + 1));
//
}
for
(
int
i
=
2
;
i
<
commands
.
size
();
i
+=
2
)
{
commandsMap
.
put
(
commands
.
get
(
i
).
toLowerCase
(),
commands
.
get
(
i
+
1
));
}
String
value
=
commands
.
get
(
2
);
...
...
src/handlers/ClientCommandHandler.java
View file @
8abed585
...
...
@@ -9,7 +9,6 @@ import util.CommandUtil;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
ClientCommandHandler
{
...
...
@@ -24,11 +23,12 @@ public class ClientCommandHandler {
public
boolean
execute
()
{
Command
command
=
CommandUtil
.
getCommand
(
commands
.
getFirst
().
split
(
" "
)[
0
]);
Command
command
=
CommandUtil
.
getCommand
(
commands
.
getFirst
());
System
.
out
.
println
(
command
);
System
.
out
.
println
(
"Command "
+
commands
);
CommandHandler
commandProcessor
=
new
CommandFactory
(
command
).
getInstance
();
List
<
String
>
commandAndArgs
=
Arrays
.
stream
(
commands
.
getFirst
().
split
(
" "
)).
toList
();
try
{
CommandInvoker
.
invoke
(
commandProcessor
,
command
AndArg
s
,
os
);
CommandInvoker
.
invoke
(
commandProcessor
,
commands
,
os
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
src/storage/Storage.java
View file @
8abed585
package
storage
;
import
jdk.incubator.vector.ByteVector
;
import
jdk.incubator.vector.VectorMask
;
import
jdk.incubator.vector.VectorOperators
;
import
jdk.incubator.vector.VectorSpecies
;
//
//
import jdk.incubator.vector.ByteVector;
//
import jdk.incubator.vector.VectorMask;
//
import jdk.incubator.vector.VectorOperators;
//
import jdk.incubator.vector.VectorSpecies;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -13,7 +13,7 @@ public class Storage {
private
final
Map
<
String
,
Long
>
timeToExpiration
=
new
ConcurrentHashMap
<>(
10000
);
private
final
Map
<
String
,
Long
>
currentTimeForKey
=
new
ConcurrentHashMap
<>(
10000
);
private
static
final
VectorSpecies
<
Byte
>
SPECIES
=
ByteVector
.
SPECIES_128
;
//
private static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_128;
private
Storage
()
{
// RdbFileReader reader = new RdbFileReader();
...
...
@@ -45,44 +45,44 @@ public class Storage {
public
String
get
(
String
key
)
{
System
.
out
.
println
(
"GET Storage: "
+
key
);
if
(
isExpired
(
key
))
{
System
.
out
.
println
(
"Key expired: "
+
key
);
return
""
;
}
//
if (isExpired(key)) {
//
System.out.println("Key expired: " + key);
//
return "";
//
}
return
storage
.
get
(
key
);
}
private
boolean
isExpired
(
String
key
)
{
long
currentTime
=
System
.
currentTimeMillis
();
if
(
timeToExpiration
.
containsKey
(
key
))
{
long
expirationTime
=
timeToExpiration
.
get
(
key
);
if
(
currentTimeForKey
.
containsKey
(
key
))
{
long
currExpiration
=
currentTimeForKey
.
get
(
key
);
long
timeDiff
=
currentTime
-
currExpiration
;
return
vectorizedComparison
(
timeDiff
,
expirationTime
);
}
else
{
return
vectorizedComparison
(
currentTime
,
expirationTime
);
}
}
return
false
;
}
private
boolean
vectorizedComparison
(
long
timeDiff
,
long
expirationTime
)
{
// Convert timeDiff and expirationTime to byte arrays for SIMD processing
byte
[]
timeDiffBytes
=
longToBytes
(
timeDiff
);
byte
[]
expirationTimeBytes
=
longToBytes
(
expirationTime
);
ByteVector
timeDiffVector
=
ByteVector
.
fromArray
(
SPECIES
,
timeDiffBytes
,
0
);
ByteVector
expirationTimeVector
=
ByteVector
.
fromArray
(
SPECIES
,
expirationTimeBytes
,
0
);
VectorMask
<
Byte
>
mask
=
timeDiffVector
.
compare
(
VectorOperators
.
GT
,
expirationTimeVector
);
return
mask
.
anyTrue
();
}
//
//
private boolean isExpired(String key) {
//
long currentTime = System.currentTimeMillis();
//
//
if (timeToExpiration.containsKey(key)) {
//
long expirationTime = timeToExpiration.get(key);
//
//
if (currentTimeForKey.containsKey(key)) {
//
long currExpiration = currentTimeForKey.get(key);
//
long timeDiff = currentTime - currExpiration;
//
return vectorizedComparison(timeDiff, expirationTime);
//
} else {
//
return vectorizedComparison(currentTime, expirationTime);
//
}
//
}
//
return false;
//
}
//
private boolean vectorizedComparison(long timeDiff, long expirationTime) {
//
// Convert timeDiff and expirationTime to byte arrays for SIMD processing
//
byte[] timeDiffBytes = longToBytes(timeDiff);
//
byte[] expirationTimeBytes = longToBytes(expirationTime);
//
//
ByteVector timeDiffVector = ByteVector.fromArray(SPECIES, timeDiffBytes, 0);
//
ByteVector expirationTimeVector = ByteVector.fromArray(SPECIES, expirationTimeBytes, 0);
//
//
//
VectorMask<Byte> mask = timeDiffVector.compare(VectorOperators.GT, expirationTimeVector);
//
//
return mask.anyTrue();
//
}
private
byte
[]
longToBytes
(
long
value
)
{
byte
[]
bytes
=
new
byte
[
8
];
...
...
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